• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Chat with ObjectOutput and InputStreams problem with null receives

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic