I’m trying to learn Ruby and Socket programming. So far I managed to
find some tutorials about Ruby and Socket programming and have made
really simple applications like a Time server sending the time to a
client. Now I wanted to try something a little more advanced. I want to
make a client that will connect to server and receive messages and at
the same time send messages to the server when certain events happen
like when there’s a file in a certain directory or a record in the
So far from the tutorials I’ve studied, the clients all just wait for a
response from the server. From what I understand once I do a gets I’ll
just be waiting for a reponse and will put the rest of the state waiting
on that response. Is it possible to do both reading and writing on the
socket at the same time?
I also did some digging on threads. I had the idea of making 2 threads
one to receive messages from the server and one to check the
directory/database then send a message. Again I don’t see though how I
can do that based on what I done in the tutorials. It seems like my
threads will just hang when I try to read from the server. Is this the
proper approach? Are there other methods aside from using threads? I saw
topic on a multiplexing server but all the examples were just waiting
again on a read from the client.
I know these are pretty broad questions and topics but hoping someone
can help clarify these issues and point me at the right direction.