codice Java
Codice: Seleziona tutto
DataOutputStream os = new DataOutputStream(socket.getOutputStream());
ByteBuffer buf = ByteBuffer.allocate(1520);
buf.put(msg.tipo.getBytes()).position(0);
buf.put(msg.Mittente.getBytes()).position(4);
buf.put(msg.Destinatario.getBytes()).position(260);
buf.put(msg.lunghezza.getBytes()).position(516);
buf.put(msg.mess.getBytes()).position(520);
byte[] baf = buf.array();
os.write(baf);Codice: Seleziona tutto
public class Msg{
private String tipo;
private String Mittente;
private String Destinatario;
private String lunghezza;
private String mess;
}Codice: Seleziona tutto
Msg msg1 = new Msg();
msg1.tipo="L";
msg1.Mittente ="";
msg1.Destinatario="";
msg1.mess= "max";
msg1.lunghezza= String.valueOf(msg1.mess.length());[SERVER]: msg_rcv: Mc.type: "76" Mc.sender: "" Mc.Receiver: "" Mc.mslen: "109" Mc.msg: "ax"
ora io so che la struttura che riceve alloca:
Mc.type -> 4 Byte
Mc.sender -> 256 Byte
Mc.Receiver -> 256 Byte
Mc.mslen -> 4 Byte
Mc.msg -> 1000 Byte
Non capisco cosa sto sbagliando nella gestione delle posizioni in BufferByte. Qualcuno riesce a spiegarmi? Grazie
