Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ClienteTask extends AsyncTask<Void,Void,Void>{
- @Override
- protected Void doInBackground(Void... params) {
- try {
- Socket socket = new Socket("192.168.8.101",9999);
- ObjectOutputStream salida = new ObjectOutputStream(socket.getOutputStream());
- Chat chat = new Chat();
- chat.setMensaje("online");
- salida.writeObject(chat);
- socket.close();
- System.out.println("Conected");
- } catch (Exception ex) {
- System.out.println("Error here" + ex.getMessage());
- }
- return null;
- }
- class Chat implements Serializable {
- private String nombre,ip,mensaje;
- //Setter
- public void setNombre(String nombre){this.nombre = nombre;}
- public void setIp(String ip){this.ip = ip;}
- public void setMensaje(String mensaje){this.mensaje = mensaje;}
- //Getter
- public String getNombre(){return nombre;}
- public String getIp(){return ip;}
- public String getMensaje(){return mensaje;}
- }
- public void run(){
- try{
- ServerSocket serverSocket = new ServerSocket(9999);
- while(true){
- Socket socket = serverSocket.accept();
- InetAddress clientIp = socket.getInetAddress(); //Get client ip
- System.out.println("The client ip is:" +clientIp.toString());
- ObjectInputStream entrada = new ObjectInputStream(socket.getInputStream());
- Chat datosMensaje = (Chat)entrada.readObject(); //HERE IS THE ERROR
- nombre = datosMensaje.getNombre();
- ip = datosMensaje.getIp();
- textoMensaje = datosMensaje.getMensaje();
- areatexto.append("n" + nombre + ": " +textoMensaje);
- Socket enviaDestinatario = new Socket("192.168.8.101", 9090);
- ObjectOutputStream datosReenvio = new ObjectOutputStream(enviaDestinatario.getOutputStream()); //Creo un socket nuevo para reenviar al cliete especificado
- datosReenvio.writeObject(datosMensaje); //Envio la informacion por el cliente deseado
- enviaDestinatario.close();
- socket.close();
- }
- }catch(Exception ex){
- System.out.println("ERROR " + ex.getMessage());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement