I am building a chat system using EventMachine and ruby on rails. It's for learning purpose.
This is how client is connecting to server.
c = TCPSocket.open(ip_address, port)
data = {:user_id => 2, :message => 'hello world'}
c.send(data)
response = c.gets
c.close
It works. However the problem is that I can't get the list of people who are currently chatting in the room because as I shown above, client is constantly opening and closing the connection.
An alternative plan is to run an EventMachine client for each connected user. I am planning to store the client connection in session for each user. In this way I will be using the same question for each user. When the user logs out then I will close the connection.
However if the user walks out then how do I self close the client connection.
Any thoughts.