Embedding Socket.IO in a non-node web-application

441 views
Skip to first unread message

Martin Gammelsæter

unread,
May 23, 2011, 5:13:02 PM5/23/11
to Socket.IO
Hi!

I have a monster of a web application written in Django, which has a
public and a private part of it. I've been asked to add a chat-
function to the internal part for cooperation and talk between the
users, and I thought immediately, after the little I've used node.js/
Socket.IO on a totally different project, that it would be a good fit
for this. Basically what it has to do is to facilitate chat between
users on the site, as well as users in an IRC-channel. I got the IRC
<--> node part down, but where I bump in to problems is trying to get
the client-side code (js served through the django/apache server) to
talk to the node deamon.

In short, my question is as follows: Is there any way I can serve all
my content with Django/apache, but have the clients themselves connect
with socket.io to my node deamon? If it helps, I obviously have the
webserver on example.com:80, and can have the node server on
example.com:whatever.

By the way, Socket.IO is a blast to work with, props to all the
contributors!

Xavi Ramirez

unread,
May 25, 2011, 11:30:08 AM5/25/11
to sock...@googlegroups.com
Would servering the chat client in it's own iframe work? If an iframe
solution is acceptable, I would recommend servering your chat program
on it's own subdomain. You can do this by configuring apache to
forward all requests to chat.example.com to localhost:8080. This is
by far the easiest solution. I use this technique to add a chat room
to this site: defuddle.me

It's possible to serve the chat client inline (i.e. not in an iframe),
but it entails fancier apache configurations.

-Xavi

2011/5/23 Martin Gammelsæter <martingam...@gmail.com>:

Serge Koval

unread,
May 25, 2011, 1:50:02 PM5/25/11
to sock...@googlegroups.com
Hi,

If you want to continue using Python, you can take a look on Tornadio
- socket.io server implementation on top of Tornado framework.
I'm pretty sure you can integrate Tornadio with Django - access your
models, etc. I use Flask-like custom framework for non-realtime part
(port 80) and a separate Tornadio instance for the realtime part of the
application (port 8000) and it just works. Only special case should be
done for Opera - it does not support cross-domain AJAX calls and does
not have websockets enabled by default. For opera you'd have to have
workaround of proxying requests from your web frontend to your socket.io
server based on URL mask and have some checks on the client side to not
go to port 8000 if it is Opera.

As for the short question: just pass 'port' parameter to the socket
constructor. Like:
var socket = new io.Socket(this.address, {
port: 8000
});

Serge.

dodi kuswono

unread,
May 25, 2011, 11:16:31 PM5/25/11
to sock...@googlegroups.com
If my team want to develop flash client for socket.io, where do we start ? Can we re-use WebSocketMain.swf ?

Serge Koval

unread,
May 26, 2011, 2:16:04 AM5/26/11
to sock...@googlegroups.com
Hi,

 You can use any client websocket implementation and add wrap your messages into socket.io protocol, which is very simple.

Thanks,
Serge.

Martin Gammelsæter

unread,
May 28, 2011, 7:44:23 AM5/28/11
to Socket.IO
On May 25, 5:30 pm, Xavi Ramirez <xavi....@gmail.com> wrote:
> Would servering the chat client in it's own iframe work?  If an iframe
> solution is acceptable, I would recommend servering your chat program
> on it's own subdomain.  You can do this by configuring apache to
> forward all requests to chat.example.com to localhost:8080.  This is
> by far the easiest solution. I use this technique to add a chat room
> to this site: defuddle.me
>
> It's possible to serve the chat client inline (i.e. not in an iframe),
> but it entails fancier apache configurations.
>
> -Xavi

This seems to be the easiest solution for me by far, as I think
getting fancy proxies or big changes in the apache config is pretty
much out of the question for this project at this point. Thank you!
Reply all
Reply to author
Forward
0 new messages