I am trying to create a server that sends objectstreamoutput to a client in array bytes and client reading it and displaying it to the screen but I am stuck in reading and writting the bytes here is my code for server:
And here is my client code:
The output for client is:
The message read by client [B@3e25a5
The length of the message read by client 0
BUILD SUCCESSFUL (total time: 0 seconds)
Welcome to the JavaRanch.
First thing I see is that you use available(). AvailableDoesntDoWhatYouThinkItDoes Next, you are creating object streams, but you aren't reading and writing objects. Have a look at the Java Tutorial page on Object Streams for how to use them correctly.
I see that. Why aren't you just writing the String objects? Why convert the Strings to byte arrays?
Also, on the receiving end, you are using available() to determine the length of the byte array. As I pointed out before, available doesn't do what you want it to do.