Good solution for two-way network socket?

Hey,

I want to make a chat app, that connects to a chat server with a background process. It gets messages from the chat server and data from the web user that it sends to the server. I was trying to use EventMachine, but it only unblocks the thread when receiving data.

The best solution I can think of is to poll one of the two directions: either get data from the web user and poll for chat data, or get data from the chat server and poll for web user data.

Anyone know of a good two-way solution, am I stuck?

Thanks, Jamie