Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

socket read-write-read-write-...

 
Ed Green
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I am trying to create a server and a client using socket and serversocket. I'm spawning a new thread on serversocket.accept(), no problem there. My problem is as follows:
Each communiction from the server and a client is an object, currently sent using objectin/outputstreams.
I have no problems doing one iteration of client-write, server-read, server write, client-read.
but i don't know how many things the client will send to a server.
the client could send a request, wait for a response, send another request, get another response, etc.
I have a while loop, dong readObject/writeObject.
The readObject() doesn't seem to be blocking when reading from the socket on client/server side. So while the client is processing whatever the server sent, i get null reads on the server. Is there any way for me to block on the server/client on the readObject() until the other side sends something?

Thank you.
 
omar bili
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
readObject() does block the while loop !
 
Ed Green
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct!
The client was rudely disconnecting and i was mishandling an exception.

thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic