0

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

user207421
  • 305,947
  • 44
  • 307
  • 483
shrram
  • 51
  • 5
  • 1
    Well it is not and should not be the same Byte[] object. But the bytes in it should be same. Log array byte by byte not as object. What you see is object's hashCode, not the bytes. – pirho Feb 25 '18 at 18:58
  • Ah .. thank you for calling it out ! – shrram Feb 25 '18 at 19:04

0 Answers0