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.