I am implementing a simple client-server program where I would like to send a 64 bit random number from the client program to the Server. I am running into an issue where the received byte array at the Server isn't same as the one sent from the client. Any assistance in figuring out the mistake would be greatly appreciated !
I used Socket send and receive byte array as a reference for my implementation.
Client program :
SecureRandom random=new SecureRandom();
byte[] r_a=new byte[8];
random.nextBytes(r_a);
DataOutputStream bos = new DataOutputStream(client_soc.getOutputStream());
bos.writeInt(r_a.length);
bos.write(r_a);
bos.flush();
bos.close();
client_soc.close();
Server program :
byte[] r_a;
DataInputStream bis= new DataInputStream(ser_soc.getInputStream());
int length_rand=bis.readInt();
if(length_rand>0)
{ r_a= new byte[length_rand];
bis.readFully(r_a,0,length_rand);
System.out.println("r_a : "+ r_a);
System.out.println("r_a length : "+ r_a.length);
}
bis.close();
ser_soc.close();
My results : Client program sends r_a : [B@78308db1
Server program received r_a : [B@2689d3df
Aucun commentaire:
Enregistrer un commentaire