<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Orbited Blog</title>
	<atom:link href="http://orbited.org/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://orbited.org/blog</link>
	<description>Blogging Comet Applications</description>
	<pubDate>Tue, 14 Oct 2008 22:53:20 +0000</pubDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
			<item>
		<title>Announcing Orbited 0.7.0</title>
		<link>http://orbited.org/blog/2008/10/announcing-orbited-070/</link>
		<comments>http://orbited.org/blog/2008/10/announcing-orbited-070/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 13:50:01 +0000</pubDate>
		<dc:creator>Michael Carter</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://orbited.org/blog/?p=222</guid>
		<description><![CDATA[Today marked the release of Orbited 0.7.0, along with the first 0.7.0 tutorial over at CometDaily. Thanks to everyone who helped with the release.

A couple of new features include:


 Embedded Stomp broker via MorbidQ. Now you put stomp:// urls in the [listen] section of the configuration
 Reworked startup api for easier use with outside projects [...]]]></description>
			<content:encoded><![CDATA[<p>Today marked the release of Orbited 0.7.0, along with the <a href="http://cometdaily.com/2008/10/10/scalable-real-time-web-architecture-part-2-a-live-graph-with-orbited-morbidq-and-jsio/">first 0.7.0 tutorial</a> over at CometDaily. Thanks to everyone who helped with the release.</p>

<p>A couple of new features include:</p>

<ul>
 <li>Embedded Stomp broker via <a href="http://www.morbidq.com">MorbidQ</a>. Now you put stomp:// urls in the [listen] section of the configuration</li>
 <li>Reworked startup api for easier use with outside projects like <a href="http://www.willowchat.org">WillowChat</a>.</li>
 <li>Improvements to the IRC client (via <a href="http://www.js.io">js.io</a>)</li>
 <li>Increased stability for Connection handling when the page is reloaded navigated away from then returned to</li>
 <li>Various small bug fixes</li>
  <li>See the commit logs and <a href="http://www.orbited.org/timeline">timeline</a>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://orbited.org/blog/2008/10/announcing-orbited-070/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Django + Orbited 0.6.x Tutorial</title>
		<link>http://orbited.org/blog/2008/09/django-orbited-06x-tutorial/</link>
		<comments>http://orbited.org/blog/2008/09/django-orbited-06x-tutorial/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 16:13:12 +0000</pubDate>
		<dc:creator>Adrian Weisberg</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://orbited.org/blog/?p=207</guid>
		<description><![CDATA[Dark Porter posted a tutorial on using Orbited with Django. Michael Carter linked to it on Comet Daily, and said:

Obviously it makes sense to migrate to separate processes for a high-concurrency production deployment, but this method is perfect for developing applications and deploying small to medium instances.

The tutorial uses a different technique than the STOMP [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://darkporter.com/?page_id=2">Dark Porter</a> posted a <a href="http://darkporter.com/?p=7">tutorial on using Orbited with Django</a>. Michael Carter <a href="http://cometdaily.com/2008/09/22/new-django-orbited-06x-tutorial/">linked to it on Comet Daily</a>, and said:</p>

<blockquote>Obviously it makes sense to migrate to separate processes for a high-concurrency production deployment, but this method is perfect for developing applications and deploying small to medium instances.</blockquote>

<p>The tutorial uses a different technique than <a href="http://orbited.org/blog/2008/09/integrating-orbited-with-web-app-frameworks/">the STOMP method</a> I described. Dark Porter takes advantage of the fact that Django and Orbited are both written in Python, and puts everything in one process, including a custom threaded TCP server.</p>
]]></content:encoded>
			<wfw:commentRss>http://orbited.org/blog/2008/09/django-orbited-06x-tutorial/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Heartbeats Handle Dropped Connections and Timeouts</title>
		<link>http://orbited.org/blog/2008/09/heartbeats-handle-dropped-connections-and-timeouts/</link>
		<comments>http://orbited.org/blog/2008/09/heartbeats-handle-dropped-connections-and-timeouts/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 00:00:33 +0000</pubDate>
		<dc:creator>Adrian Weisberg</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://orbited.org/blog/?p=149</guid>
		<description><![CDATA[The 0.6.1 release of Orbited adds a feature called heartbeats that improves dropped connection handling and also decreases reconnects due to timeouts. Dropped connection handling is important because it affects the user experience of a web application. Heartbeats are better than the previous solution of reconnecting at a fixed interval because they do a better [...]]]></description>
			<content:encoded><![CDATA[<p>The 0.6.1 release of Orbited adds a feature called heartbeats that improves dropped connection handling and also decreases reconnects due to timeouts. Dropped connection handling is important because it affects the user experience of a web application. Heartbeats are better than the previous solution of reconnecting at a fixed interval because they do a better job at a lower network cost.</p>

<h2>Dropped Connections</h2>

<p>A web application can&#8217;t prevent most dropped connections. It can only handle them in the best manner possible. Dropped connections are a problem because unless there&#8217;s some notification mechanism, the browser won&#8217;t automatically try to reestablish the connection. Furthermore, the user will think that the application is operating in a connected state, and won&#8217;t realize that they are missing messages.</p>

<p><span id="more-149"></span></p>

<p>This hurts the functionality of the application, and also decreases the user&#8217;s confidence in the application, which has negative implications for how much they use it and whether they will use it for important tasks. Preventing disturbances in the user experience and increasing user trust are both very important goals. Orbited prevents lost messages by keeping a buffer of recently sent messages, but we still want to resume normal operations as possible.</p>

<h2>Fixed Interval Reconnects</h2>

<p>A common way to handle dropped connections is to have the browser reconnect every 30 seconds, regardless of whether the connection has dropped. Prior to 0.6.1 this is what Orbited did. This method caps the period of browser unawareness at 30 seconds + the browser timeout interval. ~30 seconds is a long time for the browser to be ignorant of the connection state. The interval can be decreased, but reconnects should be avoided for 2 reasons:</p>

<ul>
<li>The browser can&#8217;t receive messages while it&#8217;s reconnecting. The connection is usually fine, so most reconnects are actually making things worse for a short period of time. </li>
<li>Each reconnect requires a full HTTP message to be sent and processed. This isn&#8217;t that bad for the client, but really adds up for the server, which is almost always the bottleneck for web applications. And some people are on dial-up or mobile connections.</li>
</ul>

<p>Fixed interval reconnects aren&#8217;t horrible, and they&#8217;re used by live deployments. But there&#8217;s a much better way.</p>

<h2>The Heartbeat Solution</h2>

<p>Orbited 0.6.1 adds a feature called heartbeats, which provide better browser awareness at a lower overhead cost than fixed interval reconnects. A &#8220;heartbeat&#8221; is a tiny amount of data (~1 byte) sent from the server to the browser without separate HTTP headers (it&#8217;s sent in the context of the Comet connection HTTP headers), meaning the cost both of bandwidth and server processing is negligible.</p>

<p>If we send a heartbeat every 5 seconds, the maximum time the browser is unaware of the connection state drops from 30 seconds + the browser timeout interval (with fixed interval reconnects) to the heartbeat timeout, which defaults to 15 seconds (the timeout is longer than the interval to account for latency). And the browser only has to reconnect if the connection drops, instead of having to reconnect every 30 seconds no matter what. The timeout and the heartbeat interval can both be lowered if necessary.</p>

<h2>Timeouts</h2>

<p>Heartbeats also prevent browser and proxy timeouts. Browsers and proxies often close open connections after around 60 seconds of inactivity. The fixed interval reconnect avoids the connection being closed unceremoniously, but since heartbeats count as activity, they prevent the timeouts from even happening. The fewer reconnects the better.</p>

<h2>Usage with Transports</h2>

<p>Orbited provides two Comet transports: streaming and long polling. Streaming provides better performance and is the default/recommended option. Both transports work with heartbeats. IE and Opera can only read heartbeats when they&#8217;re used with a streaming connection, so a long polling connection can&#8217;t use them for dropped connection handling, but they&#8217;re still handy for avoiding timeouts. Streaming with heartbeats works with most firewalls, forward proxies, reverse proxies, and routers, but if a particular deployment of intermediaries does manage to thwart streaming, the server can fall back to long-polling.</p>

<h2>What You Need to Do</h2>

<p>Probably nothing! Orbited 0.6.1 and onward use streaming with heartbeats by default. If you want you can lower the heartbeat interval and timeout for even better browser awareness of dropped connections.</p>
]]></content:encoded>
			<wfw:commentRss>http://orbited.org/blog/2008/09/heartbeats-handle-dropped-connections-and-timeouts/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Orbited 0.6.1</title>
		<link>http://orbited.org/blog/2008/09/orbited-061/</link>
		<comments>http://orbited.org/blog/2008/09/orbited-061/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 11:23:23 +0000</pubDate>
		<dc:creator>Adrian Weisberg</dc:creator>
		
		<category><![CDATA[Releases]]></category>

		<guid isPermaLink="false">http://orbited.org/blog/?p=190</guid>
		<description><![CDATA[0.6.1 is a maintenance release that fixes a number of small problems. Everyone is encouraged to upgrade. 0.6.1 also adds a new feature that&#8217;s been under development for awhile called heartbeats, which improve dropped connection handling and reduce timeouts. I&#8217;ll be writing a post on that shortly.

If you&#8217;re using a version of Orbited lower than [...]]]></description>
			<content:encoded><![CDATA[<p>0.6.1 is a maintenance release that fixes a number of small problems. Everyone is encouraged to upgrade. 0.6.1 also adds a new feature that&#8217;s been under development for awhile called heartbeats, which improve dropped connection handling and reduce timeouts. I&#8217;ll be writing a post on that shortly.</p>

<p>If you&#8217;re using a version of Orbited lower than 0.6.x, this is a great time to make the change, because <a href="http://groups.google.com/group/orbited-users/browse_thread/thread/2ce89ed5c05be260">0.6.0 marked the change</a> from alpha to beta, with the corresponding stabilization in API and core functionality. Remember to stop by the <a href="http://groups.google.com/group/orbited-users">mailing list</a>, IRC channel (#orbited on freenode or use the <a href="http://orbited.org/wiki/LiveHelp">LiveDemo</a>), and <a href="http://orbited.org/wiki/Development">Trac system</a> to participate in the development process and/or get help with Orbited.</p>
]]></content:encoded>
			<wfw:commentRss>http://orbited.org/blog/2008/09/orbited-061/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Integrating Orbited with Web App Frameworks</title>
		<link>http://orbited.org/blog/2008/09/integrating-orbited-with-web-app-frameworks/</link>
		<comments>http://orbited.org/blog/2008/09/integrating-orbited-with-web-app-frameworks/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 06:59:31 +0000</pubDate>
		<dc:creator>Adrian Weisberg</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://orbited.org/blog/?p=113</guid>
		<description><![CDATA[The simplest Orbited architecture is to have Orbited proxying messages between the TCP server and the browser using socket connections. Many people, however, choose to use web application frameworks like Django or Ruby on Rails because they helpfully abstract away certain cumbersome tasks. You can easily connect Orbited and frameworks using message queue brokers, and [...]]]></description>
			<content:encoded><![CDATA[<p>The simplest Orbited architecture is to have Orbited proxying messages between the TCP server and the browser using socket connections. Many people, however, choose to use web application frameworks like <a href="http://www.djangoproject.com/">Django</a> or <a href="http://www.rubyonrails.org/">Ruby on Rails</a> because they helpfully abstract away certain cumbersome tasks. You can easily connect Orbited and frameworks using message queue brokers, and the 0.7 release will feature an integrated basic broker.</p>

<p><span id="more-113"></span></p>

<p>Prior to 0.5, Orbited used a custom protocol (the Orbit protocol) for communication between it and the framework. Inside Orbited was a rudimentary message queue. This is the method used in the outdated <a href="http://orbited.org/wiki/0.3/CherryChat">CherryChat tutorial</a>.</p>

<p><a href="http://orbited.org/blog/wp-content/uploads/2008/09/integrated_orbit_protocol_mq.png"><img src="http://orbited.org/blog/wp-content/uploads/2008/09/integrated_orbit_protocol_mq.png" alt="Integrated Orbit Protocol MQ Architecture" title="integrated_orbit_protocol_mq" width="450" height="252" class="size-full wp-image-129" /></a></p>

<h2>Use Existing Solutions</h2>

<p>With 0.5, the team decided to switch to a standard and well-developed protocol: <a href="http://stomp.codehaus.org/Home">STOMP</a>. Instead of trying to improve the message queue functionality, we decided to focus on TCPSocket and Comet. Using STOMP allows the use of advanced stand-alone message queue brokers like <a href="http://activemq.apache.org/">ActiveMQ</a> and <a href="http://www.rabbitmq.com/">RabbitMQ</a>. It also removes the need to write and update clients for the custom Orbit protocol, since there are actively maintained STOMP clients in many languages. These benefits are similar to the benefits of the biggest change in 0.5: <a href="http://cometdaily.com/2008/07/01/sockets-in-the-browser/">TCPSocket</a>, which lets you use existing protocols for communication to the browser.</p>

<p><a href="http://orbited.org/blog/wp-content/uploads/2008/09/stand-alone_stomp_mq.png"><img src="http://orbited.org/blog/wp-content/uploads/2008/09/stand-alone_stomp_mq.png" alt="Stand-Alone STOMP MQ Architecture" title="stand-alone_stomp_mq" width="450" height="327" class="size-full wp-image-130" /></a></p>

<h2>The Super-Easy Way</h2>

<p>ActiveMQ and RabbitMQ are fairly easy to install and use, but many people wanted something even easier and simpler for testing and basic deployments. Starting with 0.7, Orbited will feature a built-in basic STOMP message queue. The message queue has already been released as a Twisted-based daemon called <a href="http://pypi.python.org/pypi/morbid/0.8.1">Morbid</a>. If you have <a href="http://peak.telecommunity.com/DevCenter/setuptools">setuptools</a> installed, type <code>easy_install morbid</code> and then run orbited and morbid. Go into the Stomp demo and it should work! Once Orbited 0.7 is released you won&#8217;t even have to install Morbid.</p>

<p><a href="http://orbited.org/blog/wp-content/uploads/2008/09/integrated_stomp_mq.png"><img src="http://orbited.org/blog/wp-content/uploads/2008/09/integrated_stomp_mq.png" alt="Integrated STOMP MQ Architecture" title="integrated_stomp_mq" width="450" height="252" class="size-full wp-image-131" /></a></p>

<h2>The Benefits in Two Sentences</h2>

<p>With the integrated STOMP message queue, you can use the same architecture as with pre-0.5 but with the added benefits of using a standard protocol. Using a stand-alone STOMP message queue broker gives you the benefits of the standard protocol plus the features and performance of advanced message queue brokers.</p>
]]></content:encoded>
			<wfw:commentRss>http://orbited.org/blog/2008/09/integrating-orbited-with-web-app-frameworks/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Contributor License Agreements</title>
		<link>http://orbited.org/blog/2008/08/contributor-license-agreements/</link>
		<comments>http://orbited.org/blog/2008/08/contributor-license-agreements/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 01:07:06 +0000</pubDate>
		<dc:creator>Adrian Weisberg</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://orbited.org/blog/?p=82</guid>
		<description><![CDATA[Michael and I have recently formed a nonprofit corporation to manage Orbited and related projects such as js.io. One of the main reasons for the nonprofit is so that contributors can sign a Contributor License Agreement (&#8221;CLA&#8221;) with an appropriate legal entity. The CLAs will protect users of the open source software projects managed by [...]]]></description>
			<content:encoded><![CDATA[<p>Michael and I have recently formed a nonprofit corporation to manage Orbited and related projects such as <a href="http://js.io/">js.io</a>. One of the main reasons for the nonprofit is so that contributors can sign a Contributor License Agreement (&#8221;CLA&#8221;) with an appropriate legal entity. The CLAs will protect users of the open source software projects managed by the nonprofit, and are a good reminder to think about intellectual property.</p>

<p><span id="more-82"></span></p>

<p>A CLA is a legal document, which means you should read it carefully. It basically gives the projects managed by the nonprofit a license to use your contributions (you retain copyright), and warrants that you have the right to give the projects that license. Most people do this implicitly when they submit code to an open source project, but a CLA puts it in writing and hopefully makes everyone aware of their responsibilities e.g. not submitting code they didn&#8217;t write, or submitting code they wrote on their employer&#8217;s time/property without their employer&#8217;s permission to license the code to an open source project. If you are doing or have done work for any of nonprofit&#8217;s software projects on your employer&#8217;s time/property, you should:</p>

<ol>
<li>Talk to your boss and make sure it&#8217;s fine that you&#8217;re working on code that will be licensed to an open source project.</li>
<li>Have them sign a corporate CLA with the nonprofit which formalizes this agreement. </li>
</ol>

<p>As a general note, anything you create on your employer&#8217;s time/property may belong to your employer. If you want to have any rights to these creations, you should have a written contract with your employer stating the the specific terms of the agreement. You should also be careful when writing and/or contributing code that&#8217;s similar to proprietary code owned by your employer. I&#8217;ll get back on topic now, as intellectual property is a very complex issue, but it&#8217;s a good idea to read a survey such as the <a href="http://www.softwarefreedom.org/resources/2008/foss-primer.html">Software Freedom Law Center&#8217;s primer</a>.</p>

<h2>The Benefits of CLA&#8217;s</h2>

<p>The main purpose of CLA&#8217;s is protecting users of the software from IP lawsuits. They also have a number of other benefits. CLA&#8217;s make it clear that contributors are under no obligation to provide support for their contribution. They make people more aware of their rights when writing code on their employer&#8217;s time/property, as mentioned above. The project itself is less likely to be attacked via lawsuits. And in general it&#8217;s good to make issues clear and explicit. CLA&#8217;s are used by many open source projects including <a href="http://www.apache.org/licenses/#clas">all the projects managed by the Apache Foundation</a>.</p>

<h2>About the CLA</h2>

<p>The CLA is between contributors and the project, which makes it distinct from an end user license e.g. the <a href="http://en.wikipedia.org/wiki/MIT_License">MIT license</a> used by Orbited. We&#8217;re using a CLA that is very similar to the one used by the Apache Foundation. The CLA&#8217;s are available on the <a href="http://orbited.org/wiki/Development">Development page</a>. You should email a scanned copy of the signed agreement to orbitedprojectREMOVETHISTEXT@gmail.com. A single CLA covers Orbited as well as all the other projects managed by the nonprofit.</p>
]]></content:encoded>
			<wfw:commentRss>http://orbited.org/blog/2008/08/contributor-license-agreements/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Orbited 0.6.0</title>
		<link>http://orbited.org/blog/2008/08/orbited-060/</link>
		<comments>http://orbited.org/blog/2008/08/orbited-060/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 21:08:24 +0000</pubDate>
		<dc:creator>Adrian Weisberg</dc:creator>
		
		<category><![CDATA[Releases]]></category>

		<guid isPermaLink="false">http://orbited.org/blog/?p=80</guid>
		<description><![CDATA[Orbited 0.6.0 has been released. See the announcements in the Google group and on Comet Daily. Work is now underway on Orbited 0.7.0, which will add two new features: stream multiplexing and integrated message queue (STOMP) server capabilities.
]]></description>
			<content:encoded><![CDATA[<p>Orbited 0.6.0 has been released. See the announcements <a href="http://groups.google.com/group/orbited-users/browse_thread/thread/2ce89ed5c05be260">in the Google group</a> and <a href="http://cometdaily.com/2008/08/13/orbited-officially-goes-beta/">on Comet Daily</a>. Work is now underway on Orbited 0.7.0, which will add two new features: <a href="http://orbited.org/ticket/58">stream multiplexing</a> and <a href="http://orbited.org/ticket/57">integrated message queue (STOMP) server capabilities</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://orbited.org/blog/2008/08/orbited-060/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Talk at OSCON 2008</title>
		<link>http://orbited.org/blog/2008/07/talk-at-oscon-2008/</link>
		<comments>http://orbited.org/blog/2008/07/talk-at-oscon-2008/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 09:20:46 +0000</pubDate>
		<dc:creator>Adrian Weisberg</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://orbited.org/blog/?p=78</guid>
		<description><![CDATA[A couple of members of the Orbited team are in Portland for the 2008 OSCON. Michael Carter and Jacob Rus are giving a talk on Wednesday about the recent developments with sockets in the browser and how they&#8217;ll make web app development easier and faster. Michael has written two articles for Comet Daily that describe [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of members of <a href="http://orbited.org/wiki/About">the Orbited team</a> are in Portland for the 2008 OSCON. Michael Carter and Jacob Rus are giving <a href="http://en.oreilly.com/oscon2008/public/schedule/detail/3048">a talk on Wednesday</a> about the recent developments with sockets in the browser and how they&#8217;ll make web app development easier and faster. Michael has written two articles for Comet Daily that describe how to use the new HTML5 WebSocket spec:</p>

<ul>
<li><a href="http://cometdaily.com/2008/07/01/sockets-in-the-browser/">Sockets in the Browser</a></li>
<li><a href="http://cometdaily.com/2008/07/04/html5-websocket/">Independence Day: HTML5 WebSocket Liberates Comet From Hacks</a></li>
</ul>

<p>Michael and Jacob will be around after the talk to chat and answer questions.</p>

<p><strong>Update</strong>: We&#8217;ve scheduled a Comet BoF for Thursday 8p-9p in room E146. Stop by to chat about anything related to Comet.</p>
]]></content:encoded>
			<wfw:commentRss>http://orbited.org/blog/2008/07/talk-at-oscon-2008/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Comet for the Non-Web Programmer</title>
		<link>http://orbited.org/blog/2008/07/comet-for-the-non-web-programmer/</link>
		<comments>http://orbited.org/blog/2008/07/comet-for-the-non-web-programmer/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 06:40:42 +0000</pubDate>
		<dc:creator>Mario Balibrera</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://orbited.org/blog/?p=77</guid>
		<description><![CDATA[the revolution
Orbited 0.5 enables a software developer to create robust, performant network applications for the web. If you know one of the common web frameworks, or are already comfortable writing PHP, for example, just download the Orbited client for your preferred language and you&#8217;re good to go. However, if you&#8217;ve never done any web work [...]]]></description>
			<content:encoded><![CDATA[<p><strong>the revolution</strong><br />
Orbited 0.5 enables a software developer to create robust, performant network applications for the web. If you know one of the common web frameworks, or are already comfortable writing PHP, for example, just download the Orbited client for your preferred language and you&#8217;re good to go. However, if you&#8217;ve never done any web work before, or are fed up with the traditional approach, you can just bypass the HTTP hacks altogether and instead write your internet application the way folks have been writing network software since the 70s - with a socket.</p>

<p><span id="more-77"></span></p>

<p>This means you stop thinking of the server as something that answers questions from the end-user, and start viewing each endpoint as an equal participant. Either side can send or receive messages whenever they want. This is a vastly more flexible, powerful programming model than the request/response paradigm that is shoved down our throats. This type of server is extremely simple to implement, requires no framework or knowledge of any protocol, and is, of course, completely platform- and language- agnostic.</p>

<p>What are the implications of this new web programming model? For starters, it means solving formerly complex problems in minutes instead of months (see Michael&#8217;s discussion of <a href="http://cometdaily.com/2008/07/01/sockets-in-the-browser/">gmail</a>), with minimal code and zero &#8220;web programming.&#8221; Because let&#8217;s face it: &#8220;web programming&#8221; just means trying to write network code on top of a protocol designed for static document transmission. This is something you can&#8217;t even attempt without a steaming pile of hacks that produce bloated architecture with serious usability issues.</p>

<p>So now that we&#8217;re in this brand new retro socket world, how do we go about making something?</p>

<!--more-->

<p><strong>use existing servers</strong><br />
I try not to dwell on it, but there was life before Al Gore invented the world wide web &#8212; it just didn&#8217;t have any meaning. There was life because there were UNIX networks inhabited by bearded sages who use terminals for everything to this day. They wrote roughly <a href="http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Registered_Ports:_1024.E2.80.9349151">3.5 bagillion protocols</a>, each with literally 100 million server implementations. Take your pick. Want a chat app? Download an <a href="http://orbited.org/wiki/JavaScriptIRCClientTutorial">IRC</a> server. How about an in-browser MMORPG with magical node clustering and load-balancing? Download <a href="http://activemq.apache.org/">ActiveMQ</a> (or any of <a href="http://www.rabbitmq.com/">10 million other Stomp brokers</a>), fire up Orbited&#8217;s Stomp client and you&#8217;re set.</p>

<p>The fact is, virtually all network applications require uninhibited bidirectional communication. This means that the second you get a browser socket, you can use any code anyone has ever written, including <a href="http://www.cyberpunkreview.com/movie/decade/2000-current/code-hunter/">Code Hunter</a>, <a href="http://en.wikipedia.org/wiki/Morse_Code">Morse Code</a>, and <a href="http://www.codered.com/">Mountain Dew Code Red</a>; and you can interact with any type of server the same way you would using telnet. You can launch a massive application without writing a line of server code. Code, code, code.</p>

<p><strong>roll your own</strong><br />
But no, you&#8217;re a unique snowflake, and you absolutely must write your own. That&#8217;s fine. It&#8217;s easy. Just get yourself a socket (there&#8217;s one in every language, and they&#8217;re all the same), wait for a connection, and talk to your client with socket.send and socket.recv. I&#8217;m telling you, you can write this type of server in about 5 lines, and develop it into a really fun game in 50 to 100 more.</p>

<p>Now, I realize that the idea of writing all your games and gizmos on top of a raw socket might make some people out there uncomfortable and a little sweaty in key areas. Naturally, no reader of this fine blog belongs to that bunch. Nevertheless, it should be noted that there are alternatives. There are seriously tons of network libraries out there. If you want a super-<a href="http://boulter.com/blog/2004/08/19/performant-is-not-a-word/">performant</a> app I&#8217;d have to recommend an asynchronous contender, such as <a href="http://www.monkey.org/~provos/libevent/">libevent</a>, <a href="http://twistedmatrix.com/trac/">Twisted</a>, or <a href="https://grizzly.dev.java.net/">Grizzly</a>. I usually use <a href="http://code.google.com/p/dez/">dez</a>.</p>

<p>Generally, this type of application will have a listener of some kind that just sits there waiting for incoming connections. Whenever someone connects, the listener passes responsibility on to an object that reads and writes. What could be simpler?</p>

<p>Since this is totally custom software, we&#8217;re going to need a protocol for the connection object to speak to the Javascript client. For anything with more than a couple command types it usually makes sense to write a JSON- or XML- based protocol, because these methods are flexible and easy to parse, and because whatever language you choose, someone&#8217;s already done the dirty work for you.</p>

<p><strong>the easy way out</strong><br />
Often, however, one or both endpoints won&#8217;t need to send anything very complex. Maybe you&#8217;re building a stock-ticker that updates a value every second, or a live message board. For these cases, you can safely use a delimiter. A delimiter is a string of characters that you know won&#8217;t ever appear elsewhere in a protocol &#8220;conversation.&#8221; Thus, the delimiter can confidently signify the end of a protocol &#8220;sentence.&#8221; Example delimiters include line break, tab, &#8220;::1337::&#8221;, and the null byte. Once you&#8217;ve chosen a delimiter, you can parse incoming messages with a very simple Javascript function.</p>

<pre><code>var separate_events = function() {
    var sep = buff.indexOf(DELIM);
    if (sep == -1) {
        return;
    }
    parse_event(eval(buff.slice(0,sep)));
    buff = buff.slice(sep+DELIM.length);
    separate_events();
}
</code></pre>

<p>This function takes a buffer string (buff) and looks for your delimiter (DELIM). If it can&#8217;t find your delimiter, the function returns. Otherwise, it knows that the first chunk of the buffer is a complete sentence, because it ends with your delimiter and starts at index 0, where the previous delimiter left off the last time this function was called. It evals this string (buff from index 0 to DELIM&#8217;s index) and passes the result to a protocol interpreter function. At this point it shifts the buffer string forward and recurses. Once you have this function in place, you just need to feed it by appending any incoming messages to the end of the buffer.</p>

<pre><code>conn.onread = read;
</code></pre>

<p>and</p>

<pre><code>var read = function(incoming_text) {
    buff += incoming_text;
    separate_events();
}
</code></pre>

<p>Now you have individual messages being sent to a function called parse_event.</p>

<pre><code>var parse_event = function(data) {
    alert("server says: "+data);
}
</code></pre>

<p>And tada! You have a basic client. I have to emphasize that it doesn&#8217;t really matter what your protocol looks like. If the application calls for it, you can just send individual letters back and forth. Alternatively, you can use XML, or have a full-fledged HTTP-like system with headers and version-variable behavior and functionality. It&#8217;s likely that your application will speak with completely different accents in different directions. Look! Tutorials: <a href="http://twistedmatrix.com/projects/core/documentation/howto/servers.html">Twisted</a>, <a href="http://www.monkey.org/~provos/libevent/doxygen-1.4.3/">libevent</a>, <a href="http://weblogs.java.net/blog/jfarcand/archive/2008/02/writing_a_tcpud_1.html">Grizzly</a>. Say hello to your mother for me. :-*</p>
]]></content:encoded>
			<wfw:commentRss>http://orbited.org/blog/2008/07/comet-for-the-non-web-programmer/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Socket Proliferation</title>
		<link>http://orbited.org/blog/2008/07/socket-proliferation/</link>
		<comments>http://orbited.org/blog/2008/07/socket-proliferation/#comments</comments>
		<pubDate>Sat, 05 Jul 2008 23:12:30 +0000</pubDate>
		<dc:creator>Michael Carter</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://orbited.org/blog/?p=75</guid>
		<description><![CDATA[Since discussing browser sockets, I&#8217;ve been doing some research on other implementations. For some time now, David Davis has had a browser socket with his Sprocket.Socket implementation.



I must give David credit for being so forward thinking, being the first to release a browser socket. With the Orbited project, we had to undergo a lengthy process [...]]]></description>
			<content:encoded><![CDATA[<p>Since <a href="http://cometdaily.com/2008/07/01/sockets-in-the-browser/">discussing browser sockets</a>, I&#8217;ve been doing some research on other implementations. For some time now, David Davis has had a browser socket with his <a href="http://xantus.vox.com/library/post/sprocketsocket.html">Sprocket.Socket implementation</a>.</p>

<p><span id="more-75"></span></p>

<p>I must give David credit for being so forward thinking, being the first to release a browser socket. With the Orbited project, we had to undergo a lengthy process to arrive at the same conclusion he had already found. We realized that we wanted reliable delivery with message ordering guarantees, so we created a protocol that we called Comet Session Protocol (CSP). Next, we started working on an API for CSP, and decided that we might as well use HTML5&#8217;s then-named TCPConnection API. We worked with that  for a while, and then realized that we weren&#8217;t actually honoring the API because we didn&#8217;t implement the server-side protocol (<a href="http://www.whatwg.org/specs/web-apps/2007-10-26/#tcp-connections">TCPConnection then</a>, like <a href="http://www.whatwg.org/specs/web-apps/current-work/#network">WebSocket now</a>, had an extra handshake for security, and framing.) So we went and implemented that, only to realize that we didn&#8217;t really need the TCPConnection security provided by the handshake &#8212; Orbited could provide it instead via access control! So we created a TCPSocket API which simulates a raw socket in the browser.</p>

<p>I must say &#8212; I am extremely impressed with David&#8217;s clear understanding of the problem domain. It took the entire Orbited core developer team a few months to follow this line of reasoning and end up where we are now.</p>

<p>Also of note, JP Calderone put together an <a href="http://jcalderone.livejournal.com/42060.html">alternative implementaiton</a> using Twisted Athena, and I imagine more will soon follow. This is great news. Having multiple browser socket implementations is exactly what we need. This way, users can experiment with the various servers and choose whichever works best for them. It leaves us free to move up the stack &#8212; That is, we can begin implementing protocols on top of our basic API. We should make sure to all choose the same basic API so that any protocol implementation can actually be used with any server.</p>

<p>For now, the Orbited project will continue protocol work with the TCPSocket interface. I think its important to keep as close to the WebSocket API as possible. Of course, I&#8217;m open to discussion from anyone interested in joining forces or providing some advice.</p>
]]></content:encoded>
			<wfw:commentRss>http://orbited.org/blog/2008/07/socket-proliferation/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
