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
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.
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?