views:

196

answers:

2

I have heard that web-based chat clients tend to use networking frameworks such as the twisted framework.

But would it be possible to build a web-based chat client without a networking framework - using only ajax connections?

I would like to build a session-based one-to-one web chat client that uses sessions to indicate when a chat has ended. Would this be possible in Rails using only ajax and without a networking framework?

What effect does it have to use a networking framework and what impact would it have on my app to not use one? Also any general recommendations for approaching this project would be appreciated.

+3  A: 

Technically speaking every network based application has a networking framework under it and, therefore, is socket based...

The only real question here is whether you want to have all that chatter go through your server or allow point to point communication. If the former, you can use the ajax framework to talk to your web server. This means that all of your clients will be constantly polling the web server for updates.

If the later, then you have to allow direct tcp connections between the two clients and need to get a little closer to the metal so to speak.

So, ask yourself this: Do you want to pay for the traffic costs AND have potential liability over divulging whatever it is that people might be typing into their client; or, would you rather just build a chat program that people can use to talk to each other?

Of course, before even going that far, do you really want to build yet another chat client? That space is already pretty crowded.

Chris Lively
+5  A: 

If i understand you correctly, you want to have to clients connect to you server and send messaged to each other to each other through ajax, via the server. This is possible, there are two approaches to do this.

The easy approach is to have both client poll every few seconds to check for new messages posted by the other. Drawback is that the messages are not instantly delivered. I think this is an example found in the rails book.

The more complex approach is to keep an open connection and sent the messages to the client as soon as they are received by the server. To do this you can use something like Juggernaut

I would like to add that though the latter works, it is not something http was meant for and it a bit of hack, but hey, whatever gets the job done. A working example of this is the rails chat project which uses a juggernaut derivative.

Arthur