# TCPSocket: Sockets in the browser

<http://ajaxian.com/archives/tcpsocket-sockets-in-the-browser>

- Host: [ajaxian.com](https://links.thingelstad.xyz/hosts/ajaxian.com/)
- Saved: July 1, 2008 (2008-07-01T18:50:36Z)
- Record: https://links.thingelstad.xyz/links/4efbcabcc3ce/
- JSON: https://links.thingelstad.xyz/links/4efbcabcc3ce.json

## From the page (probably an excerpt, not Jamie's words)

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:

PLAIN TEXT
JAVASCRIPT:







var conn = new TCPSocket(hostname, port)





conn.onopen = function() { alert('connection opened!') }


conn.onread = function(data) { alert('RECEIVE: ' + data) }


conn.onclose = function(data) { alert('connection closed!') }





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 isnt an open relay.

While this presents a paradigm shift in the way developers are tackling real-time, web-based applications today, its 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.

## Facts

- Kind: [Page](https://links.thingelstad.xyz/kinds/page/)

## Same host

- [Cross-Site XMLHttpRequest in Firefox 3](https://links.thingelstad.xyz/links/65df26b3f9a3/) (ajaxian.com, January 10, 2008)
- [ProtoFlow: Coverflow for Prototype](https://links.thingelstad.xyz/links/dd71d3010395/) (ajaxian.com, March 11, 2008)
- [IPhone WebKit Goodness: 3D CSS Transforms and ontouch events](https://links.thingelstad.xyz/links/da7d5d936929/) (ajaxian.com, April 7, 2008)
- [Steve Yegge on Server Side JavaScript](https://links.thingelstad.xyz/links/c08cd2b88726/) (ajaxian.com, June 16, 2008)
- [72photos: ProtoScripty Photo Sharing Site](https://links.thingelstad.xyz/links/15765dda03d6/) (ajaxian.com, June 18, 2008)

## Saved the same week

- [FriendFeed Finally Gets iPhone-Friendly](https://links.thingelstad.xyz/links/3e8693e5333b/) (techcrunch.com, June 30, 2008)
- [Microsoft Remote Desktop Connection 2 now available](https://links.thingelstad.xyz/links/b767f38850e8/) (tuaw.com, July 1, 2008)
- [Microsoft releases Remote Desktop Connection Client for Mac 2](https://links.thingelstad.xyz/links/2e0808315e05/) (macdailynews.com, July 1, 2008)
- [Current iPhones Keep Cheaper Plan on Reactivation](https://links.thingelstad.xyz/links/0c19e92e8ad2/) (tidbits.com, July 2, 2008)
- [Digital Photography: Get Better Fireworks Photos This Fourth of July](https://links.thingelstad.xyz/links/cf8ea91b2d98/) (lifehacker.com, July 2, 2008)

## Elsewhere

- Wayback Machine: https://web.archive.org/web/*/http://ajaxian.com/archives/tcpsocket-sockets-in-the-browser
