Devo rimanere in ascolto sulla socket, e ricevere un byte, dove all'interno vi è una struttura messaggio.
Codice: Seleziona tutto
socket = new Socket(ip.getText().toString(), Integer.parseInt(porta.getText().toString()));
MainActivity.handler.obtainMessage(0, 0, -1, "Connessione avvenita con Successo!").sendToTarget();
DataInputStream in = new DataInputStream(socket.getInputStream());
byte[] buf11 = new byte[3000];
while(flag){
in.read(buf11);
String a = new String(buf11,0,1);
if(!a.equals("\0")) {
Msg_rcv msg_rcv = new Msg_rcv();
Log.d(TAG, "msg_rcv creato");
msg_rcv.tipo_rcv = new String(buf11,0,1);
msg_rcv.mittente_rcv = new String(buf11,2,256);
msg_rcv.destinatario_rcv = new String(buf11,257,516);
msg_rcv.lunghezza_rcv = (new String(buf11,516,517));
msg_rcv.mess_rcv= new String(buf11,517,2500);
MainActivity.handler.obtainMessage(0, 0, -1, "Server: " + "tipo: " + msg_rcv.tipo_rcv + " mittente : " + msg_rcv.mittente_rcv + " destinatario: " + msg_rcv.destinatario_rcv + " lunghezza: " + msg_rcv.lunghezza_rcv + " messaggio: " + msg_rcv.mess_rcv).sendToTarget();
}
}
