This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Chat with ObjectOutput and InputStreams problem with null receives Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Chat with ObjectOutput and InputStreams problem with null receives" Watch "Chat with ObjectOutput and InputStreams problem with null receives" New topic
Author

Chat with ObjectOutput and InputStreams problem with null receives

lony mikii
Greenhorn

Joined: Mar 15, 2014
Posts: 1
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

Joined: Aug 07, 2007
Posts: 2170
    
  47
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Chat with ObjectOutput and InputStreams problem with null receives
 
Similar Threads
java.net.SocketException: Connection reset
sockets: How to receive server response in client
SMTP not working perfectly
sending an integer to a client machine
client server communication problems