WebSockets

33 views
Skip to first unread message

Saimon Moore

unread,
Dec 12, 2009, 11:51:05 PM12/12/09
to js.io
Hi,

I've been reading about how js.io (can) present(s) a WebSocket
interface to emulate WebSocket in non-complying browsers but looking
at the code I haven't been able to see where/how this is done. Is this
work on some other branch not present in github? Can someone provide
an example using js.io of how I'd go about this.

Currently I'm using a flash-based solution (via http://github.com/gimite/web-socket-js)
but I'm also targetting mobile browsers (mobile safari ) in particular
so this is not an option on mobile browser.

Let me be clear what I'm looking for. A js library that presents the
WebSocket interface to my code which utilizes WEebSockets in browsers
that support it and uses some other technology for browsers that
don't.

Regards,

Saimon

Saimon Moore

unread,
Dec 12, 2009, 11:56:32 PM12/12/09
to js.io
Searching google I found this cached link to your a websocket.js in
your previous svn repo but this is nowhere to be found in github
repo....

http://209.85.229.132/search?q=cache:LeNDfZfQdg0J:js.io/trac/changeset/65+js.io+websocket&cd=3&hl=en&ct=clnk&client=safari

On Dec 13, 5:51 am, Saimon Moore <saimonmo...@gmail.com> wrote:
> Hi,
>
> I've been reading about how js.io (can) present(s) a WebSocket
> interface to emulate WebSocket in non-complying browsers but looking
> at the code I haven't been able to see where/how this is done. Is this
> work on some other branch not present in github? Can someone provide
> an example using js.io of how I'd go about this.
>
> Currently I'm using a flash-based solution (viahttp://github.com/gimite/web-socket-js)

Mario Balibrera

unread,
Dec 13, 2009, 12:35:18 AM12/13/09
to js...@googlegroups.com
Saimon, hello. Not all the js.io 2 code has been ported over to js.io 3 yet. Try js.io 2.3.6.1:

http://cloud.github.com/downloads/mcarter/js.io/jsio-2.3.6.1.tar.gz . It comes with a compiled WebSocket client, as well a demo WebSocket application and the client code itself.


-mario


--

You received this message because you are subscribed to the Google Groups "js.io" group.
To post to this group, send email to js...@googlegroups.com.
To unsubscribe from this group, send email to jsio+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jsio?hl=en.



Saimon Moore

unread,
Dec 13, 2009, 12:36:29 AM12/13/09
to js...@googlegroups.com
Mario,

Many thanks I'll check this out asap...

Regards,

Saimon
--
Saimon Moore
Freelance Web Developer
(Available for hire - For details visit http://saimonmoore.net)

Skype: saimonmoore
Yahoo IM: saimonmoore
Google IM: saimonmoore

Saimon Moore

unread,
Dec 13, 2009, 12:46:16 AM12/13/09
to js...@googlegroups.com
Mario,

the websockets demo is pulling in a /static/Orbited.js but this file
isn't present in the bundle. Which version of Orbited should I pull
this from?

Saimon Moore

unread,
Dec 13, 2009, 1:00:24 AM12/13/09
to js...@googlegroups.com
Also am I bound to using the Orbited server or can I use this code
with any websocket protocol compliant server (.e.g
http://github.com/guille/node.websocket.js)?

Mario Balibrera

unread,
Dec 13, 2009, 1:26:56 AM12/13/09
to js...@googlegroups.com
On Sat, Dec 12, 2009 at 10:00 PM, Saimon Moore <saimo...@gmail.com> wrote:
Also am I bound to using the Orbited server or can I use this code
with any websocket protocol compliant server (.e.g
http://github.com/guille/node.websocket.js)?

Any WebSocket compliant server should work. The Orbited server just functions as a transport in the event that WebSocket is not natively supported.
 
>
> the websockets demo is pulling in a /static/Orbited.js but this file
> isn't present in the bundle. Which version of Orbited should I pull
> this from?

You should be able to use any version with a TCPSocket.

-mario

Saimon Moore

unread,
Dec 13, 2009, 1:33:57 AM12/13/09
to js...@googlegroups.com
Hi Mario,

Trying out the demo I modified things a bit to serve the demo from an
nginx virtual host.

e.g.

saimon@artemis demos $ pwd
/Users/saimon/Development/OpenSource/github/jsio-2.3.6.1/js.io/demos
saimon@artemis demos $ ls -la
total 80
drwxr-xr-x@ 14 saimon staff 476 Dec 13 07:29 ./
drwxr-xr-x@ 7 saimon staff 238 Nov 15 02:49 ../
drwxr-xr-x@ 5 saimon staff 170 Nov 15 02:49 chat/
-rw-r--r--@ 1 saimon staff 1384 Nov 15 02:42 index.html
-rw-r--r--@ 1 saimon staff 25100 Dec 13 07:16 js.io.js
drwxr-xr-x@ 3 saimon staff 102 Nov 15 02:49 lib/
drwxr-xr-x@ 5 saimon staff 170 Nov 15 02:49 mics/
lrwxr-xr-x 1 saimon staff 12 Dec 13 07:28 protocols@ -> ../protocols
drwxr-xr-x 3 saimon staff 102 Dec 13 07:13 static/
drwxr-xr-x@ 5 saimon staff 170 Nov 15 02:49 stomp/
drwxr-xr-x@ 4 saimon staff 136 Nov 15 02:49 telnet/
lrwxr-xr-x 1 saimon staff 8 Dec 13 07:29 tools@ -> ../tools
drwxr-xr-x@ 4 saimon staff 136 Nov 15 02:49 websocket/
drwxr-xr-x@ 9 saimon staff 306 Nov 15 02:49 xmpp/

and:

websocket/index.html

<!DOCTYPE html>
<html>
<head>
<title>WebSocket demo</title>
<script src='/demos/static/Orbited.js'></script>
<script src='/demos/js.io.js'></script>
<script src='/demos/websocket/websocket_demo.js'></script>
</head>
<body onload='start();'>
<input id=text value='{"a": 1}'>
<button onclick='send();'>send</button>
<div id=display></div>
</body>
</html>


and this nginx VH:


server {
listen 80;
server_name jsio.localhost;
root /Users/saimon/Development/OpenSource/github/jsio-2.3.6.1/js.io;

access_log /var/log/nginx/jsio.access.log main;
error_log /var/log/nginx/jsio.error.log debug;
}

However I'm getting the following js error which doesn't provide lots
of info as to what th real issue is.

Any clues?


http://pastie.textmate.org/private/npc5o0yasadhx49gixzyq

Regards,

Saimon

Saimon Moore

unread,
Dec 13, 2009, 1:49:37 AM12/13/09
to js...@googlegroups.com
That was with safari...

Trying firefox gives the following (no error but no connection either):

DEBUG MSPPStream setEncoding: plain
DEBUG MSPPProtocol new MSPPProtocol
DEBUG MSPPStream setMultiplexer: [object Object]
DEBUG MSPPProtocol buffering write: 1,0,localhost,8080
DEBUG MSPPStream open 1: localhost 8080 true

I forgot to mention I changed the websocket url in index.html to:

client = new js.io.protocols.websocket.Client('ws://localhost:8080/sync');

I have a node server running on localhost:8080 (accepts a bit of json
and echoes it back)

The server doesn't register any connection.

Saimon Moore

unread,
Dec 13, 2009, 1:56:11 AM12/13/09
to js...@googlegroups.com
after enabling 'Break on all error' in ff, I see it's complaining
about dojo missing.

I added dojo like this:

<!DOCTYPE html>
<html>
<head>
<title>WebSocket demo</title>
<SCRIPT TYPE="text/javascript"
SRC="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dojo/dojo.xd.js"></SCRIPT>
<script src='/demos/static/Orbited.js'></script>
<script src='/demos/js.io.js'></script>
<script src='/demos/websocket/websocket_demo.js'></script>
</head>
<body onload='start();'>
<input id=text value='{"a": 1}'>
<button onclick='send();'>send</button>
<div id=display></div>
</body>
</html>


but now it's complaining about TCPSocket missing. Next error after that is:

js.io.protocols is undefined:
js.io.protocols.websocket.Client('ws://localhost:8080/sync');\n

The Orbited.js is copied directly from the orbited 0.8 branch.

Not sure what I'm missing to get this running at this point..

Michael Carter

unread,
Dec 13, 2009, 4:15:39 AM12/13/09
to js...@googlegroups.com
What Orbited version are you using?

Saimon Moore

unread,
Dec 13, 2009, 4:51:13 AM12/13/09
to js.io
I took Orbited.js from the 0.8 branch

On 13 Δεκ, 10:15, Michael Carter <cartermich...@gmail.com> wrote:
> What Orbited version are you using?
>
> > On Sun, Dec 13, 2009 at 7:49 AM, Saimon Moore <saimonmo...@gmail.com>
> > wrote:
> > > That was with safari...
>
> > > Trying firefox gives the following (no error but no connection either):
>
> > > DEBUG MSPPStream setEncoding: plain
> > > DEBUG MSPPProtocol new MSPPProtocol
> > > DEBUG MSPPStream setMultiplexer: [object Object]
> > > DEBUG MSPPProtocol buffering write: 1,0,localhost,8080
> > > DEBUG MSPPStream open 1: localhost 8080 true
>
> > > I forgot to mention I changed the websocket url in index.html to:
>
> > > client = new
> > js.io.protocols.websocket.Client('ws://localhost:8080/sync');
>
> > > I have a node server running on localhost:8080 (accepts a bit of json
> > > and echoes it back)
>
> > > The server doesn't register any connection.
>
> > > On Sun, Dec 13, 2009 at 7:33 AM, Saimon Moore <saimonmo...@gmail.com>
> > >> <mario.balibr...@gmail.com> wrote:
> > >>> On Sat, Dec 12, 2009 at 10:00 PM, Saimon Moore <saimonmo...@gmail.com>
> > >>> wrote:
>
> > >>>> Also am I bound to using the Orbited server or can I use this code
> > >>>> with any websocket protocol compliant server (.e.g
> > >>>>http://github.com/guille/node.websocket.js)?
>
> > >>> Any WebSocket compliant server should work. The Orbited server just
> > >>> functions as a transport in the event that WebSocket is not natively
> > >>> supported.
>
> > >>>> > the websockets demo is pulling in a /static/Orbited.js but this file
> > >>>> > isn't present in the bundle. Which version of Orbited should I pull
> > >>>> > this from?
>
> > >>> You should be able to use any version with a TCPSocket.
>
> > >>> -mario
>
> > >>> --
>
> > >>> You received this message because you are subscribed to the Google
> > Groups
> > >>> "js.io" group.
> > >>> To post to this group, send email to js...@googlegroups.com.
> > >>> To unsubscribe from this group, send email to
> > >>> jsio+uns...@googlegroups.com<jsio%2Bunsu...@googlegroups.com>
> > .
> > >>> For more options, visit this group at
> > >>>http://groups.google.com/group/jsio?hl=en.
>
> > >> --
> > >> Saimon Moore
> > >> Freelance Web Developer
> > >> (Available for hire - For details visithttp://saimonmoore.net)
>
> > >> Skype: saimonmoore
> > >> Yahoo IM: saimonmoore
> > >> Google IM: saimonmoore
>
> > > --
> > > Saimon Moore
> > > Freelance Web Developer
> > > (Available for hire - For details visithttp://saimonmoore.net)
>
> > > Skype: saimonmoore
> > > Yahoo IM: saimonmoore
> > > Google IM: saimonmoore
>
> > --
> > Saimon Moore
> > Freelance Web Developer
> > (Available for hire - For details visithttp://saimonmoore.net)
>
> > Skype: saimonmoore
> > Yahoo IM: saimonmoore
> > Google IM: saimonmoore
>
> > --
>
> > You received this message because you are subscribed to the Google Groups "
> > js.io" group.
> > To post to this group, send email to js...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > jsio+uns...@googlegroups.com <jsio%2Bunsu...@googlegroups.com>.

Saimon Moore

unread,
Dec 13, 2009, 4:59:30 AM12/13/09
to js.io
So just to be sure things are clear here is my setup:

node.websockets.js server running on localhost 8080
I'm running the websockets demo via an nginx virtual host
(with modifications as described above)
The demo html file calles for an /static/Orbited.js which I copied
over from the 0.8 branch
error in ff console showed dojo missing. Using dojo from Google
latest error is missing TCPSocket

On 13 Δεκ, 10:51, Saimon Moore <saimonmo...@gmail.com> wrote:
> I took Orbited.js from the 0.8 branch
>

Michael Carter

unread,
Dec 13, 2009, 4:59:51 AM12/13/09
to js...@googlegroups.com
I would very much suggest avoiding 0.8 for this particular endeavor, at least for now. Use the latest 0.7.x.

2009/12/13 Saimon Moore <saimo...@gmail.com>
To unsubscribe from this group, send email to jsio+uns...@googlegroups.com.

Saimon Moore

unread,
Dec 13, 2009, 5:02:59 AM12/13/09
to js...@googlegroups.com
Ok. Ill try it with the 0.7 release

Thanks

Saimon

Saimon Moore

unread,
Dec 14, 2009, 4:46:15 AM12/14/09
to js.io
mcarter: I'm continuing my experiments in getting the websocket demo
setup. Using Orbited.js from the 0.7 branch was an improvement. I also
realised that I needed to remove the call to the dojo source as the
packagemanager is allready embedded in js.io.js.

However, I'm now coming up against the following error: GET
http://jsio.localhost/tcp 404 Not Found (55ms)


I think though that up till now I haven't really grasped the
underlying technology but I think I'm beginning to get the picture.

e.g. Orbited.js talks to the orbited python server which sets up a tcp
connection over http and acts like a gateway/proxy forwarding the
connection requests on to their final destination.

Please correct me where I'm mixing things up?

In which case for the websockets demo I'm going to need the orbited
python server running and also configure nginx so that requests coming
for /tcp are forwarded to the orbited server which will then proxy the
connection on to the websocket server?

On Dec 13, 11:02 am, Saimon Moore <saimonmo...@gmail.com> wrote:
> Ok. Ill try it with the 0.7 release
>
> Thanks
>
> Saimon
>
> 13 Δεκ 2009, 10:59, ο/η Michael Carter <cartermich...@gmail.com>  
> έγραψε:
>
>
>
> > I would very much suggest avoiding 0.8 for this particular endeavor,  
> > at least for now. Use the latest 0.7.x.
>
> > 2009/12/13 Saimon Moore <saimonmo...@gmail.com>

Saimon Moore

unread,
Dec 14, 2009, 5:27:47 AM12/14/09
to js.io
I've installed the python orbited server as per the installation docs.

I have it configured like this:

# Example Orbited Configuration file
[global]
reactor=select
# reactor=epoll
# reactor=kqueue
proxy.enabled = 1
session.ping_interval = 40
session.ping_timeout = 30
user=saimon

[listen]
http://:8000
# uncomment to enable ssl on port 8043 using given .key and .crt files
#https://:8043
#
#[ssl]
#key=orbited.key
#crt=orbited.crt

[static]

[access]
# localhost:8000 -> irc.freenode.net:6667
#websocket server
* -> localhost:8080

[logging]
debug=STDERR,debug.log
info=STDERR,info.log
access=STDERR,info.log
warn=STDERR,error.log
error=STDERR,error.log

#Don't enable debug by default
enabled.default=debug,info,access,warn,error

# Turn debug on for the "Proxy" logger
[loggers]
Proxy=debug,info,access,warn,error


I have an nginx virtual host configured like this:

upstream orbited {
server 127.0.0.1:8000;
}

server {
listen 80;
server_name jsio.localhost;
root /Users/saimon/Development/OpenSource/github/jsio-2.3.6.1/js.io;

access_log /var/log/nginx/jsio.access.log main;
error_log /var/log/nginx/jsio.error.log debug;

location ~ (/tcp/) {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect false;
proxy_pass http://orbited;
}
}

I have a node.js-based websocket server running on localhost:8080

The demo code:

client = new js.io.protocols.websocket.Client('ws://localhost:8080/
sync');

Note: /sync is a resource on the websocket server

In firefox I'm now getting:

connecting...
connection closed


In console:

http://screencast.com/t/NDE3NDE4ZD

From orbited python server:

saimon@artemis 0.7(master) $ sudo orbited
12/14/09 11:18:43:489 INFO orbited.start using select reactor
12/14/09 11:18:43:569 DEBUG orbited.cometsession.Port
startingListening
12/14/09 11:18:43:569 DEBUG orbited.cometsession.Port adding into
existing resource as tcp
12/14/09 11:18:43:569 INFO orbited.start proxy protocol active
12/14/09 11:18:43:571 INFO orbited.start Listening http@8000
12/14/09 11:18:43:572 INFO orbited.start switching to user saimon
(uid=501) and group saimon (gid=501)
/Library/Python/2.6/site-packages/orbited-0.7.10-py2.6.egg/orbited/
cometsession.py:455: DeprecationWarning: twisted.web.error.NoResource
is deprecated since Twisted 9.0. See twisted.web.resource.NoResource.
return error.NoResource("<script>alert('whoops');</script>")

The websocket-server received no connection attempts.

Not sure how to proceed at this point.

Regards,

Saimon

On Dec 14, 10:46 am, Saimon Moore <saimonmo...@gmail.com> wrote:
> mcarter: I'm continuing my experiments in getting the websocket demo
> setup. Using Orbited.js from the 0.7 branch was an improvement. I also
> realised that I needed to remove the call to the dojo source as the
> packagemanager is allready embedded in js.io.js.
>
> However, I'm now coming up against the following error: GEThttp://jsio.localhost/tcp404 Not Found (55ms)

Saimon Moore

unread,
Dec 14, 2009, 5:55:29 AM12/14/09
to js.io
After finding this:

http://orbited.org/ticket/113

I changed my nginx config to:

server {
listen 80;
server_name jsio.localhost;
root /Users/saimon/Development/OpenSource/github/jsio-2.3.6.1/js.io;

access_log /var/log/nginx/jsio.access.log main;
error_log /var/log/nginx/jsio.error.log debug;

location /static/ {
proxy_pass http://127.0.0.1:8000/static/;
}

location /tcp {
proxy_pass http://127.0.0.1:8000/tcp;
proxy_buffering off;
tcp_nodelay on;
access_log off;
}
}

But I'm still getting the same issue as above...
>                 proxy_passhttp://orbited;
> > However, I'm now coming up against the following error: GEThttp://jsio.localhost/tcp404Not Found (55ms)
> > > > > > >>>> with any websocket protocol compliant...
>
> read more »

Saimon Moore

unread,
Dec 16, 2009, 9:23:05 AM12/16/09
to js.io
Hi all,

I'm still quite stuck at this point though I'm beginning to suspect
that this has more to do with my nginx setup.

I'd really appreciate any help.

Regards,

Saimon

On Dec 14, 11:55 am, Saimon Moore <saimonmo...@gmail.com> wrote:
> After finding this:
>
> http://orbited.org/ticket/113
>
> I changed my nginx config to:
>
> server {
>         listen       80;
>         server_name  jsio.localhost;
>         root /Users/saimon/Development/OpenSource/github/jsio-2.3.6.1/js.io;
>
>         access_log  /var/log/nginx/jsio.access.log  main;
>         error_log   /var/log/nginx/jsio.error.log debug;
>
>         location /static/ {
>                         proxy_passhttp://127.0.0.1:8000/static/;
>         }
>
>         location /tcp {
>                 proxy_passhttp://127.0.0.1:8000/tcp;
> > > However, I'm now coming up against the following error: GEThttp://jsio.localhost/tcp404NotFound (55ms)
> > > > > > > >>  <body...
>
> read more »
Reply all
Reply to author
Forward
0 new messages