I have some troubles with receiving data on server side. Here goes the code:
on client part i have :
public void sendMessage(byte[] bytes) throws IOException {
byte[] lenghtInBytes = ByteBuffer.allocate(4).putInt(bytes.length).array();
out.write(lenghtInBytes,0,4);
out.write(bytes,0,bytes.length);
out.flush();
}
on server part i have function:
public byte[] receiveMessage() throws IOException, ClassNotFoundException {
byte[] lenghtInBytes = new byte[4];
in.read(lenghtInBytes,0,4);
int length = ByteBuffer.wrap(lenghtInBytes).getInt();
serverLogger.debug(length);
byte[] data = new byte[length];
in.read(data,0, length);
serverLogger.debug(new String(data));
return data;
}
in server main :
out = new BufferedOutputStream(sslClientSocket.getOutputStream());
out.flush();
in = new BufferedInputStream(sslClientSocket.getInputStream());
System.out.println(new String(receiveString()));
System.out.println(new String(receiveString()));
in client main :
sendMessage(firstData.getBytes());
sendMessage(secondData.getBytes());
as a result on server side i receive only firstdata correctly, and secondData is empty(is 0). Why is this happens?
The problem was due to the fact that on the server side was used jre6, while client application was running on jre7.