Am Mon, 20 Sep 2004 16:31:53 +0900 schrieb Yohanes Santoso: > Brian Schröäer <ruby / brian-schroeder.de> writes: > >> Hello Group, >> >> I'm writing a simple chat client-server as an introductory example, and >> now I'm wondering about some things. >> >> First: Do I have to make TCPSocket#puts TCPSocket#gets thread save by >> using mutexes? >> >> Second: Is there a possibility do use push rather than poll for reading >> the Socket. (If it is already threadsafe, then there is nothing to do >> here, but if not, I'd have to peek the TCPSocket, and send afterwards if >> nothing was in the pipe). Otherwise I could just have a reading and a >> sending thread. >> >> Thank you, >> >> Brian > > First: Yes, they are thread safe. However, I think you still want to > synchronise access to the socket otherwise it is like two people > talking at once: confusion. Then again, this depends on the nature of > the protocol you are using (app-level protocol). > > Second: you can use IO.select() to determine the readability (and > writeablity) of a socket. Or you can just use reading and sending > threads. Your choice. > > YS. Hello Yohanes, in the program only one thread at a time is reading, and only one at a time is writing. I wanted to know if I could read and write to the same socket from two different threads simultaneously. And I think this is a subset of the answer, so I take it for "yes". Thanks for the answer! regards, Brian