You are on page 1of 1

private ObjectOutputStream output; private Socket client; private String message; public Emisor() { } @Override public void run()

{ try { System.out.println("Buscando Servidor ..."); client = new Socket(InetAddress.getByName("192.168.1.4"), 12345); System.out.println("Connection " + " received from: " + client.getIn etAddress().getHostName()); output = new ObjectOutputStream(client.getOutputStream()); output.flush(); // flush output buffer to send header information } catch (IOException ioException) { //Logger.getLogger(Emisor.class.getName()).log(Level.SEVERE, null, e x); ioException.printStackTrace(); } catch (NullPointerException ex) { } while (true){ //Solicita el ingreso de un nuevo mensaje en la consola para enviarl o Scanner mensaje = new Scanner(System.in); message = mensaje.nextLine(); try // send object to client { output.writeObject("Gabby>>> " + message); output.flush(); // flush output to client } // end try catch (IOException ioException) { System.out.println("\n Error al escribir el objeto"); } } // // // // // // // // // } System.out.println("\n Fin de la conexion ..............."); try { output.close(); // close output stream connection.close(); // close socket } // end try catch (IOException ioException) { ioException.printStackTrace(); } // end catch

You might also like