File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes How to break blocked write operation??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "How to break blocked write operation???" Watch "How to break blocked write operation???" New topic
Author

How to break blocked write operation???

Amit Ghilidyal
Greenhorn

Joined: Mar 14, 2000
Posts: 2
Hi
I have a chat server sort of utility which apart from
the normal chat messages also sends lot of other real time
messages to the clients. I have multithreaded server application
with each thread handling a particular client. I perform read
operation in the thread. The messages that need to be broadcast
to other clients are maintained in a single queue. Each message
has a list of clients to be sent to. I then
extract the message from the queue and send them to the respective clients. The issue is since i have a single function
which enumerates through the clients for the message, i am facing
the problem that if the write operation to a socket
is stalled for any reason(if the client is slow or crashes) then
the server stalls. I need a way to break the write operation since i have other clients to be sent the messages.
i want to contine sending messages to at least the other clients
I don't like the idea of spawning a separate thread for every
write operation. And then killing the thread. I wonder with
so many chat server utilities being written, how they are managing
this issue?
amit


amit_doon
Rolf Weasel
Ranch Hand

Joined: Feb 26, 2000
Posts: 82
what if when u enumerate through the list of clients for a message, instead of having this thread itself do the sending, pass the message to the thread handling the concerned client. Let that thread do the sending since it handles the client anyways. a block won't affect anybody else.


May the Moose be with you.
amit lo
Greenhorn

Joined: Feb 19, 2007
Posts: 4
Thanx
I guess ultimately i need to implement a separate queue
for every client and have another thread launched for writing
to the client. So that makes two threads for every client.
since one would be reading and the other writing. I can have a single thread , but since read operation is blocked, i can
timeout on read and then write, in that case i will need to
have one thread. But i tried on linux machine with jdk1.1.8 timeout
does not work , it gives me error while it works fine on solaris.
On solaris interruptedexception gets thrown but on linux(Red hat
5.0) i am not able to trap it.
Anyway i would like to know that is this workaround the only possible way of handling blocked writes.
How do people writing
client server networking applications tackle this problem since
this is such a known issue?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to break blocked write operation???