• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: sockets & ObjectStream

 
Xavier Fabreguettes
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using sockets instead of RMI and I send across data using ObjectStream. For each client request, I establish a new connection, send the request, retrieve the response and then close the connection. This works fine and I am relatively happy with it.
However, I would like to know if people in a similar situation have done things that way or, instead, if they open a connection per client, service all the requests of the same client via this connection and then close the connection. I tried this approach initially but got errors when trying to use an infinite loop in the client (loop on read from stream). This is what is typically done with InputStream and I know it works (checked it), but there seems to be more to it when you use ObjectStream.
Any suggestion would be appreciated.
Cheers,
Xavier
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't use Sockets, so my suggestion might be completely off the mark. But here goes anyway.
If on the server you have a Daemon thread always listening for requests. Then when a client starts up and makes its first request, the Daemon thread can fire off a new thread for that client. The reference to this thread is now passed back to the client. The client uses this unique thread for its calls. Wouldn't the connection always be open as long as the client holds onto the reference to its server thread?
Mark
 
Xavier Fabreguettes
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
thanks for your email. Your option might well work but this is not really the way I'd like to go as I'd prefer the sever threads to be transparent to the clients. What I am after is more a way to loop on readObject() functions a bit like we can do with Datastream using something like " while (in.readLine()) {...}".
Cheers,
xavier
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic