Tuesday, July 1st, 2008

TCPSocket: Sockets in the browser

Category: Comet

Michael Carter of Orbited has written about how he now likes to call Comet sockets in the browser, and has an implementation available that looks like this:

javascript

  1. var conn = new TCPSocket(hostname, port)
  2.  
  3. conn.onopen = function() { alert('connection opened!') }
  4. conn.onread = function(data) { alert('RECEIVE: ' + data) }
  5. conn.onclose = function(data) { alert('connection closed!') }
  6.  
  7. conn.send('Hello World');

The above code code is all you need to know. It will open a TCP connection to hostname:port, and will send the data “Hello World”. Any data the server sends back will be alerted with the onread handler.

The exact mechanism behind this innovation is pretty straightforward: Orbited is a router and firewall for incoming TCPSocket connections from the browser. It uses Comet techniques to establish bi-directional communication with the browser, then forwards all data over a raw TCP socket to the end point. Configuration allows access control enforcement so that the TCPSocket can only be connected to pre-approved end-points, so that the Orbited server isn’t an open relay.

While this presents a paradigm shift in the way developers are tackling real-time, web-based applications today, it’s actually a return to the original method of writing network applications. Instead of writing applications based on web frameworks and throwing a Comet server in the mix, you can simply use the client-server architecture where the browser is the client, and the server is an arbitrary TCP server.

Posted by Dion Almaer at 12:50 pm
3 Comments

++++-
4.2 rating from 26 votes

3 Comments »

Comments feed TrackBack URI

What’s the downside?

Comment by Nosredna — July 1, 2008

how come sockets avalibable? ActiveX or Flash-based?

Comment by KKFC — July 1, 2008

Sprocket.Socket was the first client side pseduo-socket
http://xantus.vox.com/library/post/sprocketsocket.html

Michael seems to be copying my ideas, first Cometd -> Orbitd, now browser sockets

Comment by Xantus — July 2, 2008

Leave a comment

You must be logged in to post a comment.