Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chat with ObjectOutput and InputStreams problem with null receives

 
lony mikii
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Im pretty new with Java, and I'm trying to develop a TCP chat with a server, and clients who can connect to it.
I started out using Scanner and PrintWriter, but since its not the way I wanted it to be, I notice that using objects and implementing Serializable is much more precise in transferring data.

EDIT
I managed to solve half of the problem, by implementing write and read Unshared.
But now I have some other issue.

How to sort the incoming data to the server to send it to a proper place.

So this is my server Thread run loop, and when the ObjectInputStream reads some data, how can I "read" it so it knows to what if statement to go to.
I was here experimenting with the Scanner, so you can ignore that part.

 
Tony Docherty
Bartender
Posts: 2952
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Chat services by their very nature are text based services and so I'm surprised to hear you need to use Object streams. What requirement do you have that can't be handled by sending plain text?

So this is my server Thread run loop, and when the ObjectInputStream reads some data, how can I "read" it so it knows to what if statement to go to.

Not sure what you mean here. When you read the data from the ObjectInputStream you use the appropriate readXXX method to get the type of data that was sent, be it a primitive value or an object. If your sender could be sending anything (ie you don't know what order they will be sending stuff in) then they will need to wrap it in some type of collections class and then send the collection class because you need to know what primitives/objects you will be receiving and in what order. But as I said earlier I'm not convinced you need to be using Object streams at all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic