• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Server and Client

 
feda alshahwan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
run:
The message read by client [B@3e25a5
The length of the message read by client 0
[B@3e25a5
BUILD SUCCESSFUL (total time: 0 seconds)


How to solve it please?
 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
feda alshahwan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing using in the webserver and reading using in the client
 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic