(also related to the other thread about websockets)
Last time I did this using two server apps: 1) a Rails app with all my business logic, and 2) a Faye server (actually a Sinatra app) whose job is only to do the pub/sub part. The client connects to the Faye server and the Faye server can send messages directly to the client via websockets.
When someone writes a chat message, it goes through the Rails app, and then the Rails app sends a message to the Faye server telling the Faye server to publish the chat message.
This was the most effective solution I found but I'm sure there are different architectures.
check out...