Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package printers; import java.awt.print.PrinterException; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataOutputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.net.ServerSocket; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStreamWriter; import java.net.Socket; import java.util.logging.Level; import java.util.logging.Logger; import org.json.simple.JSONObject; /** * * @author carlos */ public class Printers { /** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException, PrinterException { try { ServerSocket server = new ServerSocket(4500); while (true) { Socket cliente = server.accept(); String sendString = ""; //ObjectOutputStream salida = new ObjectOutputStream(cliente.getOutputStream()); //ObjectInputStream entrada = new ObjectInputStream(cliente.getInputStream()); //BufferedReader entrada = new BufferedReader(new InputStreamReader(cliente.getInputStream())); //BufferedWriter socketWriter = new BufferedWriter(new OutputStreamWriter(cliente.getOutputStream())); BufferedReader entrada = new BufferedReader(new InputStreamReader(cliente.getInputStream())); DataOutputStream salida = new DataOutputStream(cliente.getOutputStream()); getPrinter printer = new getPrinter(); //JSONObject obj = new JSONObject(); //obj.put("printers", printer.searshPrinter()); //sendString = String.join("|", printer.searshPrinter()); try { String mensajeRecibido = entrada.readLine(); String[] mensajeRecibidoArr = mensajeRecibido.split("\\|"); System.out.println(mensajeRecibido); System.out.println(printer.setPrinting(mensajeRecibidoArr)); //System.out.println(printer.savePdf(mensajeRecibidoArr)); //salida.writeUTF(sendString); //System.out.println(sendString); //socketWriter.write("hola"); cliente.close(); } catch (IOException ex) { Logger.getLogger(Printers.class.getName()).log(Level.SEVERE, null, ex); } } } catch (IOException ex) { Logger.getLogger(Printers.class.getName()).log(Level.SEVERE, null, ex); } } }