aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes socket read-write-read-write-... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "socket read-write-read-write-..." Watch "socket read-write-read-write-..." New topic
Author

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

Ed Green
Greenhorn

Joined: Jun 15, 2004
Posts: 11
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

Joined: Aug 13, 2004
Posts: 177
hi
readObject() does block the while loop !
Ed Green
Greenhorn

Joined: Jun 15, 2004
Posts: 11
Correct!
The client was rudely disconnecting and i was mishandling an exception.

thank you
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: socket read-write-read-write-...