<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>source code bean &#187; Web</title>
	<atom:link href="http://sourcecodebean.com/archives/category/web/feed" rel="self" type="application/rss+xml" />
	<link>http://sourcecodebean.com</link>
	<description>thoughts and ideas from a .net developer</description>
	<lastBuildDate>Sat, 26 May 2012 09:45:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Protothon #2 &#8211; WebRTC</title>
		<link>http://sourcecodebean.com/archives/protothon-2-webrtc/1625</link>
		<comments>http://sourcecodebean.com/archives/protothon-2-webrtc/1625#comments</comments>
		<pubDate>Sun, 25 Mar 2012 20:05:56 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=1625</guid>
		<description><![CDATA[Yesterday I went to a hackathon called Protothon. Protothon describes itself as &#8220;Space for the place between code and creativity&#8221; and the idea is to bring together programmers, creatives and entrepreneurs together and under a very limited time build an application from scratch. The focus of this hackathon was WebRTC, which is a new standard [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I went to a hackathon called Protothon. <a href="http://protothon.com/">Protothon</a> describes itself as &#8220;Space for the place between code and creativity&#8221; and the idea is to bring together programmers, creatives and entrepreneurs together and under a very limited time build an application from scratch. The focus of this hackathon was <a href="http://www.webrtc.org/">WebRTC</a>, which is a new standard for Real Time Communications using HTML5/Javascript. At the moment it is so new that no browser actually supports it yet, but there are special builds of Chrome and Firefox in which you can enable it.  So the task of this hackaton was basically to do something cool with WebRTC.</p>
<p>The team I was in consisted of me, <a href="https://twitter.com/blog2t">Tomek Augustyn</a>, <a href="https://twitter.com/#!/spathon">Patrik Spathon</a> and <a href="https://twitter.com/#!/seducedbylight">Pebbles Lim</a>. Tother we came up with the idea to build a multiplayer version of the classic game pong, but using motion detection to control the game. We named the game Spong:</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2012/03/Screen-Shot-2012-03-25-at-7.51.51-PM.png"><img src="http://sourcecodebean.com/wp-content/uploads/2012/03/Screen-Shot-2012-03-25-at-7.51.51-PM.png" alt="" title="Screen Shot 2012-03-25 at 7.51.51 PM" width="700" class="aligncenter size-full wp-image-1627" /></a></p>
<p>Each player runs the game from his web browser, which will access his web cam using WebRTC. The motion detector analyzes the video stream and detects where the most amount of movement is, this gives us a coordinate on the screen. The Y part of this coordinate is used to control the position of the players&#8217; paddle. You can see this in the image above where the cross points out where i just moved my hand. Each players&#8217; movements is sent to the other player via a Node.js/Socket.IO relay server. </p>
<p>To summarize Protothon #2 I must say that I was really impressed with all the applications presented by the different teams. It was one intense day, but a lot of fun! I am looking forward to attending again in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/protothon-2-webrtc/1625/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Serving your ASP.NET MVC site on Nginx / fastcgi-mono-server4</title>
		<link>http://sourcecodebean.com/archives/serving-your-asp-net-mvc-site-on-nginx-fastcgi-mono-server4/1617</link>
		<comments>http://sourcecodebean.com/archives/serving-your-asp-net-mvc-site-on-nginx-fastcgi-mono-server4/1617#comments</comments>
		<pubDate>Tue, 20 Mar 2012 21:20:39 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=1617</guid>
		<description><![CDATA[In my previous post I showed you how to compile and install mono and get your MVC site up running using the development web server xsp4. The next step is to serve your site using a real web server, my choice is nginx. First, we need a configuration file for the nginx site. If you [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://sourcecodebean.com/archives/deploying-your-asp-net-mvc3-site-on-mono/1589">previous post</a> I showed you how to compile and install mono and get your MVC site up running using the development web server xsp4. The next step is to serve your site using a real web server, my choice is nginx. </p>
<p>First, we need a configuration file for the nginx site. If you haven&#8217;t already got nginx installed, install it (<code>sudo apt-get install nginx</code>).</p>
<p>/etc/nginx/sites-enabled/mvc:</p>
<pre>
server {
    listen   80;
    server_name mvctest.sourcecodebean.com;
    root  /home/peter/MonoMvcDeploy/;

    location / {
      root /home/peter/MonoMvcDeploy/;
      index index.html index.htm default.aspx Default.aspx;
      fastcgi_index /Home;
      fastcgi_pass 127.0.0.1:8000;
      include /etc/nginx/fastcgi_params;
    }
}
</pre>
<p><span id="more-1617"></span></p>
<p>Type &#8220;sudo service nginx reload&#8221; to reload the configuration. Browsing to the site should give you a fastcgi error since there is no fastcgi server listening on 127.0.0.1:8000 yet. So far this is a good thing and shows that your configuration is correct. </p>
<p>Next we create a start script for our fastcgi server.</p>
<p>/home/peter/startmvc:</p>
<pre>
#!/bin/bash
source ./monoenv.sh
fastcgi-mono-server4 /applications=/:/home/peter/MonoMvcDeploy/ /socket=tcp:127.0.0.1:8000
</pre>
<p>This is pretty straigt forward, the only thing that might be a bit confusing is this part &#8220;/:/home/peter/MonoMvcDeploy/&#8221;. This means that we want to map the URL / to the application in /home/peter/MonoMvcDeploy/. This allows us to run several applications in the same fastcgi server on different URLs. </p>
<p>Now try running the script and browse to your site, our sample MVC site should appear! </p>
<p>The last step is to create a upstart script to have our application start automatically at system boot</p>
<p>/etc/init/mvc.conf:</p>
<pre>
#!upstart
description "sionmailer web"
author      "peter"

start on startup
stop on shutdown

respawn

script
    echo $$ > /var/run/mvc.pid
    exec sudo -H -u peter /home/peter/startmvc 2>&#038;1
end script

pre-start script
    echo "[`date`] (sys) Starting" >> /var/log/mvc.sys.log
end script

pre-stop script
    rm /var/run/mvc.pid
    echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/mvc.sys.log
end script
</pre>
<p>Save the config file and start the site: <code>service mvc start</code>. </p>
<p>All done, your site is being served by nginx/fastcgi-mono-server4!</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/serving-your-asp-net-mvc-site-on-nginx-fastcgi-mono-server4/1617/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SignalRChat &#8211; Using RxJS to add live notificaitons</title>
		<link>http://sourcecodebean.com/archives/signalrchat-using-rxjs-to-add-live-notificaitons/1321</link>
		<comments>http://sourcecodebean.com/archives/signalrchat-using-rxjs-to-add-live-notificaitons/1321#comments</comments>
		<pubDate>Mon, 24 Oct 2011 17:25:14 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=1321</guid>
		<description><![CDATA[I have been playing around a little with Reactive Extensions for javascript and must say that I am really impressed. RxJS a port of the .NET based version which is, as they describe it on their site, &#8220;a library to compose asynchronous and event-based programs using observable collections and LINQ-style query operators.&#8220;. So what does [...]]]></description>
			<content:encoded><![CDATA[<p>I have been playing around a little with Reactive Extensions for javascript and must say that I am really impressed. RxJS a port of the .NET based version which is, as they describe it on <a href="http://msdn.microsoft.com/en-us/data/gg577609">their site</a>, &#8220;<em>a library to compose asynchronous and event-based programs using observable collections and LINQ-style query operators.</em>&#8220;. So what does this mean? Let me give you an example.</p>
<p>I wanted to add a live notification function to the chat, as soon as someone is typing, three dots should appear next to the user&#8217;s name. This means that as soon as the user starts we need to send a message to the server, this message is then broadcasted to all the connected clients. To not flood the server and the users, maximum one message per second should be sent.</p>
<p>Keydown &#8211; time since last message >= 1 second, or this is the first keydown in the sequence  => send message<br />
Keydown &#8211; time since last message < 1 second  => do nothing</p>
<p>There is a built in method called Throttle that does almost this, we could use it, but then the first keystroke would get delayed and I did not want this. So being a beginner at RX I struggled for a while trying to get to where I wanted. I came up with a solution that did what it I wanted, but it was not so elegant. Then I found <a href="http://stackoverflow.com/questions/5197032/how-to-take-first-occurrence-and-then-supress-events-for-2-seconds-rxjs">this post</a> on StackOverflow, with a solution by Sergey Aldoukhov that solved the problem in a very elegant way, so I just decided to use it instead. Sergey had created an extension method called OneInTime, this is the code:</p>
<blockquote><div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">Rx.<span class="me1">Observable</span>.<span class="me1">prototype</span>.<span class="me1">OneInTime</span> = <span class="kw2">function</span> <span class="br0">&#40;</span>delay<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">this</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; .<span class="me1">Take</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; .<span class="me1">Merge</span><span class="br0">&#40;</span>Rx.<span class="me1">Observable</span>.<span class="me1">Empty</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">Delay</span><span class="br0">&#40;</span>delay<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; .<span class="me1">Repeat</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
</ol>
</div>
</blockquote>
<p>So what does this mean? <span id="more-1321"></span>Take(1) is the simple part, we take 1 event from the stream. The merge expression is used to merge multiple IObservable streams into single IObservable stream. Each value on the source streams is projected into the result stream until all source streams complete. The Repeat method with no argument will repeatedly sub­scribe to the same observable collection indefinitely. So by taking one, merging with the delayed empty stream and then calling Repeat(), we take one event from the stream, and then skips all the events during the next second. After one second we repeat. Exactly what we wanted to achieve! </p>
<p>And this is how I would use it in the chat (#msg is the text input):</p>
<blockquote><div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span><span class="st0">&quot;#msg&quot;</span><span class="br0">&#41;</span>.<span class="me1">toObservable</span><span class="br0">&#40;</span><span class="st0">&quot;keypress&quot;</span><span class="br0">&#41;</span> <span class="co1">// Create an observable from the keypress event</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; .<span class="me1">OneInTime</span><span class="br0">&#40;</span><span class="nu0">1000</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; .<span class="me1">Subscribe</span><span class="br0">&#40;</span><span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> chat.<span class="me1">userTyping</span><span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
</blockquote>
<p>Pretty neat right?</p>
<p>The code is live at <a href="http://signalrchat.apphb.com/">http://signalrchat.apphb.com/</a> and you can find the source on <a href="https://github.com/moberg/SignalRChat">GitHub</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/signalrchat-using-rxjs-to-add-live-notificaitons/1321/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Updated version of SignalRChat</title>
		<link>http://sourcecodebean.com/archives/updated-version-of-signalrchat/1315</link>
		<comments>http://sourcecodebean.com/archives/updated-version-of-signalrchat/1315#comments</comments>
		<pubDate>Fri, 07 Oct 2011 08:10:55 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=1315</guid>
		<description><![CDATA[Yesterday I uploaded a slightly updated version of the test application I have built using SignalR. Besides from looking much better, it now uses the high level Hubs API (instead of the connection API) that SignalR provides. You find it here: http://signalrchat.apphb.com/ And you can find the source on GitHub: http://github.com/moberg/SignalRChat]]></description>
			<content:encoded><![CDATA[<p>Yesterday I uploaded a slightly updated version of the test application I have built using SignalR. Besides from looking much better, it now uses the high level Hubs API (instead of the connection API) that SignalR provides. </p>
<p>You find it here: <a href="http://signalrchat.apphb.com/">http://signalrchat.apphb.com/</a></p>
<p>And you can find the source on GitHub: <a href="http://github.com/moberg/SignalRChat">http://github.com/moberg/SignalRChat</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/updated-version-of-signalrchat/1315/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SignalR &#8211; Real time web for .NET</title>
		<link>http://sourcecodebean.com/archives/signalr-real-time-web-for-net/1297</link>
		<comments>http://sourcecodebean.com/archives/signalr-real-time-web-for-net/1297#comments</comments>
		<pubDate>Mon, 26 Sep 2011 21:17:28 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=1297</guid>
		<description><![CDATA[SignalR is a library for .NET to help build real time web applications, in a way it is quite similar to Socket.IO on Node.js. It consists of three main parts: SignalR.Server &#8211; .NET code running on IIS SignalR.Js &#8211; A SignalR client in javascript SignalR.Client &#8211; A SignalR client in .NET. Useful for communicating with [...]]]></description>
			<content:encoded><![CDATA[<p>SignalR is a library for .NET to help build real time web applications, in a way it is quite similar to Socket.IO on Node.js. It consists of three main parts:</p>
<ul>
<li>SignalR.Server &#8211; .NET code running on IIS</li>
<li>SignalR.Js &#8211; A SignalR client in javascript</li>
<li>SignalR.Client &#8211; A SignalR client in .NET. Useful for communicating with a SignalR server from, for example, a Windows Phone application. </li>
</ul>
<p>SignalR is using long polling as a method to keep its http connections open. In the future support for WebSockets is going to be added as well (a guess would be when .NET 4.5/IIS8 is released, it will have support for WebSockets).</p>
<p>Let me show you how simple it is to create a chat server. First start Visual Studio and create a ASP.NET MVC3 application. When you have created your project you want to add SignalR from NuGet, so open up the NuGet manager and search for SignalR. You need the SignalR.Server and SignalR.Js packages.</p>
<p><span id="more-1297"></span><br />
When SignalR has installed we need to create the actual server, so lets add a new class,  MyConnection. This class will handle the asynchronous communication with the clients:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">using System;</div>
</li>
<li class="li1">
<div class="de1">using System.<span class="me1">Web</span>.<span class="me1">Script</span>.<span class="me1">Serialization</span>;</div>
</li>
<li class="li1">
<div class="de1">using SignalR;</div>
</li>
<li class="li2">
<div class="de2">using System.<span class="me1">Threading</span>.<span class="me1">Tasks</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">namespace SignalRTest</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; public class MyConnection : PersistentConnection</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; protected override Task OnReceivedAsync<span class="br0">&#40;</span><span class="kw4">string</span> clientId, <span class="kw4">string</span> jsonData<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Deserialize json string</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var data = new JavaScriptSerializer<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span class="me1">Deserialize</span><span class="br0">&#40;</span>jsonData, typeof<span class="br0">&#40;</span>EventData<span class="br0">&#41;</span><span class="br0">&#41;</span> as EventData;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Broadcast data to all clients</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> Connection.<span class="me1">Broadcast</span><span class="br0">&#40;</span><span class="kw4">string</span>.<span class="me1">Format</span><span class="br0">&#40;</span><span class="st0">&quot;{0} {1}: {2}&quot;</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DateTime.<span class="me1">Now</span>.<span class="me1">ToShortTimeString</span><span class="br0">&#40;</span><span class="br0">&#41;</span>, data.<span class="me1">ClientName</span>, data.<span class="me1">Message</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; public class EventData</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; public <span class="kw4">string</span> ClientName <span class="br0">&#123;</span> get; set; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; public <span class="kw4">string</span> Message <span class="br0">&#123;</span> get; set; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>To route the traffic to MyConnection we need to modify Global.asax slightly:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">public <span class="kw4">static</span> <span class="kw4">void</span> RegisterRoutes<span class="br0">&#40;</span>RouteCollection routes<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; routes.<span class="me1">IgnoreRoute</span><span class="br0">&#40;</span><span class="st0">&quot;{resource}.axd/{*pathInfo}&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; routes.<span class="me1">MapConnection</span>&lt;MyConnection&gt;<span class="br0">&#40;</span><span class="st0">&quot;echo&quot;</span>, <span class="st0">&quot;echo/{*operation}&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; routes.<span class="me1">MapRoute</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;Default&quot;</span>, <span class="co1">// Route name</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;{controller}/{action}/{id}&quot;</span>, <span class="co1">// URL with parameters</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; new <span class="br0">&#123;</span> controller = <span class="st0">&quot;Home&quot;</span>, action = <span class="st0">&quot;Index&quot;</span>, id = UrlParameter.<span class="me1">Optional</span> <span class="br0">&#125;</span> <span class="co1">// Parameter defaults</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>And the last part, the UI. Put this into your Home/Index.cshtml view:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;h2 id=<span class="st0">&quot;subtitle&quot;</span>&gt;Join the chat&lt;/h2&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;div&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;script type=<span class="st0">&quot;text/javascript&quot;</span>&gt;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> connection = $.<span class="me1">connection</span><span class="br0">&#40;</span><span class="st0">&#8216;echo&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> clientName = <span class="st0">&#8221;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> send = <span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>$<span class="br0">&#40;</span><span class="st0">&#8216;#msg&#8217;</span><span class="br0">&#41;</span>.<span class="me1">val</span><span class="br0">&#40;</span><span class="br0">&#41;</span> !== <span class="st0">&#8221;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; connection.<span class="me1">send</span><span class="br0">&#40;</span><span class="st0">&quot;{Message: &#8216;&quot;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + $<span class="br0">&#40;</span><span class="st0">&#8216;#msg&#8217;</span><span class="br0">&#41;</span>.<span class="me1">val</span><span class="br0">&#40;</span><span class="br0">&#41;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + <span class="st0">&quot;&#8217;, ClientName: &#8216;&quot;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + clientName + <span class="st0">&quot;&#8217;}&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&quot;#msg&quot;</span><span class="br0">&#41;</span>.<span class="me1">val</span><span class="br0">&#40;</span><span class="st0">&#8221;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> startChatting = <span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>$<span class="br0">&#40;</span><span class="st0">&#8216;#name&#8217;</span><span class="br0">&#41;</span>.<span class="me1">val</span><span class="br0">&#40;</span><span class="br0">&#41;</span> !== <span class="st0">&#8221;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clientName = $<span class="br0">&#40;</span><span class="st0">&#8216;#name&#8217;</span><span class="br0">&#41;</span>.<span class="me1">val</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&quot;#info&quot;</span><span class="br0">&#41;</span>.<span class="me1">toggle</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&quot;#chat&quot;</span><span class="br0">&#41;</span>.<span class="me1">toggle</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#8216;#msg&#8217;</span><span class="br0">&#41;</span>.<span class="kw3">focus</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#8216;#subtitle&#8217;</span><span class="br0">&#41;</span>.<span class="me1">html</span><span class="br0">&#40;</span><span class="st0">&quot;Now chatting&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&quot;#chat&quot;</span><span class="br0">&#41;</span>.<span class="me1">toggle</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#8216;#name&#8217;</span><span class="br0">&#41;</span>.<span class="kw3">focus</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; connection.<span class="me1">received</span><span class="br0">&#40;</span><span class="kw2">function</span> <span class="br0">&#40;</span>data<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#8216;#messages&#8217;</span><span class="br0">&#41;</span>.<span class="me1">append</span><span class="br0">&#40;</span><span class="st0">&#8216;&lt;li&gt;&#8217;</span> + data + <span class="st0">&#8216;&lt;/li&gt;&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&quot;#broadcast&quot;</span><span class="br0">&#41;</span>.<span class="me1">click</span><span class="br0">&#40;</span><span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; send<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&quot;#start&quot;</span><span class="br0">&#41;</span>.<span class="me1">click</span><span class="br0">&#40;</span><span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; startChatting<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#8216;#chatform&#8217;</span><span class="br0">&#41;</span>.<span class="me1">submit</span><span class="br0">&#40;</span><span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; send<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#8216;#startform&#8217;</span><span class="br0">&#41;</span>.<span class="me1">submit</span><span class="br0">&#40;</span><span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; startChatting<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; connection.<span class="me1">start</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;/script&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;div id=<span class="st0">&quot;info&quot;</span>&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;form id=<span class="st0">&quot;startform&quot;</span>&gt; &nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Enter your <span class="kw3">name</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=<span class="st0">&quot;text&quot;</span> id=<span class="st0">&quot;name&quot;</span> &nbsp;/&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=<span class="st0">&quot;button&quot;</span> id=<span class="st0">&quot;start&quot;</span> value=<span class="st0">&quot;Start chatting&quot;</span> /&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;/form&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;/div&gt;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;div id=<span class="st0">&quot;chat&quot;</span>&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;form id=<span class="st0">&quot;chatform&quot;</span>&gt; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;ul id=<span class="st0">&quot;messages&quot;</span>&gt;&lt;/ul&gt;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=<span class="st0">&quot;text&quot;</span> id=<span class="st0">&quot;msg&quot;</span> &nbsp;/&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=<span class="st0">&quot;button&quot;</span> id=<span class="st0">&quot;broadcast&quot;</span> value=<span class="st0">&quot;Send&quot;</span> /&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;/form&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;/div&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p>Alright, that should be all. Compile and run it! You can test out my chat live over at AppHarbor:</p>
<p><a href="http://signalrchat.apphb.com/">http://signalrchat.apphb.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/signalr-real-time-web-for-net/1297/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>My first Google Chrome Extension &#8211; E24.se cleanup</title>
		<link>http://sourcecodebean.com/archives/my-first-google-chrome-extension-e24-se-cleanup/1286</link>
		<comments>http://sourcecodebean.com/archives/my-first-google-chrome-extension-e24-se-cleanup/1286#comments</comments>
		<pubDate>Tue, 02 Aug 2011 10:12:49 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=1286</guid>
		<description><![CDATA[Occasionally i read the swedish news site e24.se. One thing that really annoys me about the site is the fixed banner they have on top of all the article pages. I decided to do something about it so i created a Google Chrome Extension that removes the banner, and as a bonus it also removes [...]]]></description>
			<content:encoded><![CDATA[<p>Occasionally i read the swedish news site e24.se. One thing that really annoys me about the site is the fixed banner they have on top of all the article pages. I decided to do something about it so i created a Google Chrome Extension that removes the banner, and as a bonus it also removes all the ads on the page. Enjoy:</p>
<p><a href="https://chrome.google.com/webstore/detail/lffoakndkbfaoglgbnaagjglhhlapdnk?hl=sv&#038;hc=search&#038;hcp=main">https://chrome.google.com/webstore/detail/lffoakndkbfaoglgbnaagjglhhlapdnk?hl=sv&#038;hc=search&#038;hcp=main</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/my-first-google-chrome-extension-e24-se-cleanup/1286/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Realtime connections between web servers and web browsers</title>
		<link>http://sourcecodebean.com/archives/realtime-connections-between-web-servers-and-web-browsers/1211</link>
		<comments>http://sourcecodebean.com/archives/realtime-connections-between-web-servers-and-web-browsers/1211#comments</comments>
		<pubDate>Tue, 05 Jul 2011 19:01:41 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=1211</guid>
		<description><![CDATA[In the early days of the web, web pages were very static in content, once the page was loaded nothing on the page would change until you reloaded it. Then came Ajax and allowed us to do partial reloads of the page. During the last few years the web has evolved even more. Today you [...]]]></description>
			<content:encoded><![CDATA[<p>In the early days of the web, web pages were very static in content, once the page was loaded nothing on the page would change until you reloaded it. Then came Ajax and allowed us to do partial reloads of the page. During the last few years the web has evolved even more. Today you see a lot of web applications, such as Facebook and Google+, where content is updated as you are watching the page. This has been made possible by using different techniques to keep a connection to the web server open and be able to push content from the web server to the connected clients. The main technique to allow this in web browsers today is what is called Comet. </p>
<h3 style=''>Comet &#8211; using browser connections</h3>
<p>Comet is a web application model in which a long-held HTTP request allows a web server to push data to client browsers, without the browser explicitly requesting it. It works the way that the web browser requests an url from the server, and the server deliberately keeps it open, allowing it to work as a stream of data between the server and the client web browser. In this stream the web server can push content to the client.  <span id="more-1211"></span></p>
<p>Keeping connections open for such a long time is not how HTTP requests was intended to be used, so a lot of people have been describing this as a hack. The biggest problem with Comet has been that the HTTP 1.1 specification states that a web browser should not have more than two simultaneous connections to a web server. By using Comet, one of these connections would always be held open for push notifications. Only having one available connection could limit the browser. An example could be that the browser may be blocked from sending a new request while waiting for the results of a previous request while loading a series of images. Most sites solved this by creating a separate sub domain for the real time communication. Also, getting Comet to work properly in all web browsers isn&#8217;t at all trivial. So what other options are there?</p>
<h3 style='padding-top:10px;'>Comet &#8211; using Flash sockets</h3>
<p>Flash sockets is based on the same idea as Comet. On the server side it is very similar to the regular use of Comet, but on the client side the connection to the server is kept open by using a Flash Socket running in a flash application. Since the HTTP connection is opened by Flash it will work the same way in all web browsers, but the downside is of course that it requires Flash, so many mobile browsers will not be able to use it. The Flash socket implementation is considered as more stable and not as much as a hack as the browser Comet implementation. However, it is considered a temporary solution until most web browsers have implemented support for WebSockets. </p>
<h3 style='padding-top:10px;'>WebSockets &#8211; The replacement for Comet</h3>
<p>WebSockets is a technology for providing bi-directional, full-duplex communications channels, over a single TCP socket and is supposed to be able to replace the different Comet solutions that exists today. The API is being standardized by the W3C and is currently implemented in Chrome 4+ and Safari 5+. It is also implemented in Firefox and Opera, but disabled by default. As usual, Internet Explorer is lagging behind and no support for WebSockets exists as of today. Maybe in Internet Explorer 10, who knows&#8230; So it will be a while until WebSockets are so widely accepted that we can only rely on WebSockets.</p>
<h2 style='padding-top:15px;'>On the server side</h2>
<p>To allow for Comet connections the web server needs to support long lived HTTP connections. Most web servers were not built for this, so implementing Comet on a web server such as IIS can be a bit of a challenge, especially when scaling to lots of concurrent users.</p>
<p>Holding lots of concurrent connections open is something that Node.js is very good at (<a href="http://sourcecodebean.com/archives/javascript-on-the-server-side/1161">I blogged about Node.js a few weeks ago</a>), and not supprisingly there are many Comet notification servers built on it. The two most popular implementations seems to be <a href="https://github.com/maccman/juggernaut">Juggernaut</a> and <a href="http://faye.jcoglan.com/">Faye</a>. Lets get into a crash course in how to start using Juggernaut.</p>
<h3 style='padding-top:10px;'>Juggernaut</h3>
<p>Juggernaut is a push notification server for WebSockets with a easy fallback to Flash sockets if the clients web browser does not support it. Getting started with Juggernaut is very easy, I got my server up running in just a few minutes. Let me show you how to do it on OSX.</p>
<p>First, if you don&#8217;t already have <a href="http://mxcl.github.com/homebrew/">Homebrew</a> (a Unix package manager for OSX) installed, go ahead and install it:</p>
<blockquote><p><code>$ curl -LsSf https://github.com/mxcl/homebrew/tarball/master | sudo /usr/bin/tar xvz -C/usr/local --strip 1<br />
</code></p></blockquote>
<p>Now install Node.js, Redis (key/value data strore server, the Juggernaut server and the Juggernaut gem (if you want the Ruby support). Follow the instructions for each package.</p>
<blockquote><p><code>$ brew install node<br />
$ brew install redis<br />
$ npm install juggernaut<br />
$ gem install juggernaut<br />
</code></p></blockquote>
<p>Now start Redis and Juggernaut:</p>
<blockquote><p><code>$ redis-server &#038;<br />
$ node ~/node_modules/juggernau/server.js  &#038;<br />
</code></p></blockquote>
<p>Juggernaut is by default hosted on port 8080 and it should now be possible to browse to <a href="http://localhost:8080/application.js">http://localhost:8080/application.js</a>. This is the javascript that Juggernaut clients should load in order to communicate with the server. </p>
<p>Now lets create an HTML file, jugtest.html, and host it on a local web server:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;script</span> <span class="re0">src</span>=<span class="st0">&quot;http://localhost:8080/application.js&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;text/javascript&quot;</span> <span class="re0">charset</span>=<span class="st0">&quot;utf-8&quot;</span><span class="re2">&gt;</span></span><span class="sc3"><span class="re1">&lt;/script<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;script</span> <span class="re0">type</span>=<span class="st0">&quot;text/javascript&quot;</span> <span class="re0">charset</span>=<span class="st0">&quot;utf-8&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; var jug = new Juggernaut;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; jug.subscribe(&quot;channel1&quot;, function(data){</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; alert(data)</div>
</li>
<li class="li1">
<div class="de1">&nbsp; });</div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/script<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Also, let&#8217;s create a simple Ruby script, test.rb, to send notifications:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">require</span> <span class="st0">&quot;juggernaut&quot;</span></div>
</li>
<li class="li1">
<div class="de1">Juggernaut.<span class="me1">publish</span><span class="br0">&#40;</span><span class="st0">&quot;channel1&quot;</span>, <span class="st0">&quot;Hello world!&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Everything should be setup now, let&#8217;s browse jugtest.html, my webserver runs on port 3000, so for me that is <a href="http://localhost:3000/jugtest.html">http://localhost:3000/jugtest.html</a>. Nothing shows up in the web browser, but in the terminal running Juggernaut we should be able to see that one client has connected. Lets run the ruby script:</p>
<blockquote><p><code>$ ruby test.rb<br />
</code></p></blockquote>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/07/helloworld.png"><img src="http://sourcecodebean.com/wp-content/uploads/2011/07/helloworld.png" alt="" title="helloworld" width="479" height="201" class="aligncenter size-full wp-image-1224" /></a></p>
<p>The message shows up in the web browser, it works! </p>
<p>As you can see getting started with push notifications using Juggernaut is very easy. If you have any experience with other push notification servers, please leave a comment, it would be interesting to hear your experiences!</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/realtime-connections-between-web-servers-and-web-browsers/1211/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript on the server side</title>
		<link>http://sourcecodebean.com/archives/javascript-on-the-server-side/1161</link>
		<comments>http://sourcecodebean.com/archives/javascript-on-the-server-side/1161#comments</comments>
		<pubDate>Tue, 07 Jun 2011 20:45:21 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=1161</guid>
		<description><![CDATA[For the last decade javascript has been a language that has almost exclusively been run on the client side, in the web browser. But during the past year it seems like Javascript has found its way to the server side as well, to the joy of some developers while others wrinkle their nose and wonders [...]]]></description>
			<content:encoded><![CDATA[<p>For the last decade javascript has been a language that has almost exclusively been run on the client side, in the web browser. But during the past year it seems like Javascript has found its way to the server side as well, to the joy of some developers while others wrinkle their nose and wonders why you would ever use Javascript for something more advanced than client side processing. </p>
<p>The fact is that Javascript is a very powerful language, unfortunately it has had a bad reputation for many years. I admit, for a long time I also looked at JavaScript as a second-class citizen in the programming world. A programming language used only to glue together HTML pages, while the heavy lifting was done on the server side in C#, Java, Ruby or in any other &#8220;real&#8221; language. However, my view of Javascript has drastically changed during the last few years. The language have &#8220;grown up&#8221;, and by that I don&#8217;t really mean the language itself, instead I am thinking about the libraries and tools available for Javascript, such as jQuery, JSON, Node.js, and HTML5. jQuery was a major game changer on the client side and now we have Node on the server side. </p>
<p>Node is a low level framework for building high performance web applications. It contains of an interpreter based on Google&#8217;s V8 and a framework library. HTTP is a first class protocol in Node and it is very easy to get a web server up running. <span id="more-1161"></span>The main difference from traditional frameworks is that Node is event driven (asynchronous). While most webservers use synchronous thread pool based request handling, Node server will only run one event loop which will handle all incoming requests using callbacks. Asynchronus web servers are proved to be very fast, for example the Nginx and Lighthttpd web servers, and Node is not an exception. </p>
<p>Let me show you what the simplest web server in Node looks like:</p>
<p><code>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> http = require<span class="br0">&#40;</span><span class="st0">&quot;http&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">http.<span class="me1">createServer</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>request, response<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; response.<span class="me1">writeHead</span><span class="br0">&#40;</span><span class="nu0">200</span>, <span class="br0">&#123;</span><span class="st0">&quot;Content-Type&quot;</span>: <span class="st0">&quot;text/html&quot;</span><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; response.<span class="kw1">write</span><span class="br0">&#40;</span><span class="st0">&quot;Hello World!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; response.<span class="me1">end</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">listen</span><span class="br0">&#40;</span><span class="nu0">1234</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p></code></p>
<p>Running the program will start a web server listening on port 1234 and visiting http://localhost:1234 will show a &#8220;Hellow World!&#8221; message to the visitor. </p>
<p>The main difference when writing code for Node is that you have to understand is that blocking IO should be avoided. Everything runs in parallell except your code, writing blocking code will prevent Node from serving other requests. This is an example of writing blocking code:</p>
<p><code>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> http = require<span class="br0">&#40;</span><span class="st0">&quot;http&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> url = require<span class="br0">&#40;</span><span class="st0">&quot;url&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">http.<span class="me1">createServer</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>request, response<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; response.<span class="me1">writeHead</span><span class="br0">&#40;</span><span class="nu0">200</span>, <span class="br0">&#123;</span><span class="st0">&quot;Content-Type&quot;</span>: <span class="st0">&quot;text/html&quot;</span><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> pathName = url.<span class="me1">parse</span><span class="br0">&#40;</span>request.<span class="me1">url</span><span class="br0">&#41;</span>.<span class="me1">pathname</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>pathName == <span class="st0">&quot;/longrun&quot;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">function</span> sleep<span class="br0">&#40;</span>milliSeconds<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> startTime = <span class="kw2">new</span> Date<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getTime</span><span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="co1">// get the current time</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span><span class="kw2">new</span> Date<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getTime</span><span class="br0">&#40;</span><span class="br0">&#41;</span> &lt; startTime + milliSeconds<span class="br0">&#41;</span>; <span class="co1">// hog cpu</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; sleep<span class="br0">&#40;</span><span class="nu0">10000</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; response.<span class="kw1">write</span><span class="br0">&#40;</span><span class="st0">&quot;Long run...&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; response.<span class="me1">end</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; response.<span class="kw1">write</span><span class="br0">&#40;</span><span class="st0">&quot;Hello World!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; response.<span class="me1">end</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">listen</span><span class="br0">&#40;</span><span class="nu0">1234</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p></code></p>
<p>The above example listens to two urls http://localhost:1234 and http://localhost:1234/longrun. When first visiting / it loads fast. Loading the /longrun takes 10 seconds as expected (think of this as database query or some other IO operation that takes long time), but it also causes Node to block and not serve new requests until /longrun has completed. To avoid this you should use non blocking IO at all times. By doing this, Node will be able to process other requests while waiting for the request to complete.</p>
<p>For a more in depth introduction to Node I can recommend the short book &#8220;<a href="http://nodebeginner.org/">The Node Beginner Book</a>&#8221; and also the blog post <a href="http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/">&#8220;Understanding the node.js event loop&#8221;</a></p>
<p>To get started with Node I suggest you head over to Github and follow the intallation instructions to install Node and npm (the package manager for Node) <a href=" https://github.com/joyent/node/wiki/Installation"> https://github.com/joyent/node/wiki/Installation</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/javascript-on-the-server-side/1161/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Nginx: Protecting a folder using htaccess</title>
		<link>http://sourcecodebean.com/archives/nginx-protecting-a-folder-using-htaccess/1094</link>
		<comments>http://sourcecodebean.com/archives/nginx-protecting-a-folder-using-htaccess/1094#comments</comments>
		<pubDate>Mon, 18 Apr 2011 07:19:50 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=1094</guid>
		<description><![CDATA[First we need to install the htpasswd application, it is located in the apache2-utils package. This package has no dependencies on apache, so it is safe to install it &#8211; it will not download the full apache for you To install it on ubuntu type: sudo apt-get install apache2-utils Once installed we can use it [...]]]></description>
			<content:encoded><![CDATA[<p>First we need to install the htpasswd application, it is located in the apache2-utils package. This package has no dependencies on apache, so it is safe to install it &#8211; it will not download the full apache for you <img src='http://sourcecodebean.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>To install it on ubuntu type:</p>
<p><code>sudo apt-get install apache2-utils</code></p>
<p>Once installed we can use it to create an htaccess file.</p>
<p><code>htpasswd -c -b /path/to/htpasswd NewUser NewPassword</code></p>
<p>Now we need to add one block to the nginx config. Bellow is the config for this site, the part in bold is what needs to be added.</p>
<p><code></p>
<pre>
server {
    listen   80;
    server_name sourcecodebean.com;

    index index.php index.html;
    root /path/to/web/root;

 <strong>   location ^~ /secret-dir/ {
        auth_basic            "Restricted";
        auth_basic_user_file  /path/to/htpasswd;
    }</strong>

    location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9200;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  /path/to/web/root$fastcgi_script_name;
    }
}</pre>
<p></code></p>
<p>Woho! All done!</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/nginx-protecting-a-folder-using-htaccess/1094/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AppHarbor &#8211; Heroku for .NET?</title>
		<link>http://sourcecodebean.com/archives/appharbor-heroku-for-net/987</link>
		<comments>http://sourcecodebean.com/archives/appharbor-heroku-for-net/987#comments</comments>
		<pubDate>Wed, 06 Apr 2011 20:24:31 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=987</guid>
		<description><![CDATA[I have been reading about this new startup that offers a service called AppHarbor. It seems very much as the same idea as Heroku for Ruby, but for .NET. The basic idea is that you deploy your code by pushing your code onto the server using Git, the server then builds, runs unit tests and [...]]]></description>
			<content:encoded><![CDATA[<p>I have been reading about this new startup that offers a service called AppHarbor. It seems very much as the same idea as <a href="http://heroku.com/">Heroku for Ruby</a>, but for .NET. The basic idea is that you deploy your code by pushing your code onto the server using Git, the server then builds, runs unit tests and deploys your application. Super simple!</p>
<p>When I first read about AppHarbor I got the impression that is was running ontop of Microsoft Azure, which turned out to be all wrong. AppHarbor is running in the Amazon Cloud on EC2 instances. When it comes to databases AppHarbor provides access to MySQL and MSSQL. Interestingly they recommend users to use MySQL:</p>
<blockquote><p><a href="http://blog.appharbor.com/2011/01/12/mysql-support">&#8220;we expect to be able to offer MySQL on faster hardware and with more redundancy than SQL Server at the same price point. If you are planning to build an app on top of AppHarbor and have the option, we recommend you go with MySQL.&#8221;</a></p></blockquote>
<p>Another interesting choice is that they have chosen <a href="http://support.appharbor.com/kb/getting-started/information-about-our-load-balancer">Nginx as their proxy/load balancer</a>.</p>
<p>Ok, let me show you how easy it is to create a simple ASP.NET MVC 3 application and deploy it on AppHarbour <span id="more-987"></span> The first step is to go to <a href="http://appharbor.com">appharbor.com</a> and register an account. Once created you will be able to create your first app:</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/1.png"><img class="aligncenter size-full wp-image-995" title="1" src="http://sourcecodebean.com/wp-content/uploads/2011/03/1.png" alt="" width="600" /></a></p>
<p>Give your application and press create. You have done all the configuring you need to do at AppHarbor.</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/2.png"><img class="aligncenter size-full wp-image-996" title="2" src="http://sourcecodebean.com/wp-content/uploads/2011/03/2.png" alt="" width="600" /></a></p>
<p>Lets create a MVC 3 project with unit tests:</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/3.png"><img class="aligncenter size-full wp-image-997" title="3" src="http://sourcecodebean.com/wp-content/uploads/2011/03/3.png" alt="" width="600" /></a><br />
<a href="http://sourcecodebean.com/wp-content/uploads/2011/03/4.png"><img class="aligncenter size-full wp-image-998" title="4" src="http://sourcecodebean.com/wp-content/uploads/2011/03/4.png" alt="" width="600" /></a></p>
<p>Make sure your project builds and that the tests passes. Also make sure you have Git installed, if not you can fetch it from <a href="http://code.google.com/p/msysgit/downloads/list">here</a>. Now open a shell and cd into the folder where you created your application.</p>
<p>First we need to configure git with your name, the email you used to register at AppHarbor and last the git postBuffer size:</p>
<blockquote><p><code>PS C:\dev\appharbor\MyCoolApp&gt; git config --global user.name SourceCodeBean<br />
PS C:\dev\appharbor\MyCoolApp&gt; git config --global user.email mail@sourcecodebean.com<br />
PS C:\dev\appharbor\MyCoolApp&gt; git config --global http.postBuffer 52428800</code></p></blockquote>
<p>After this we initiate the git repository:</p>
<blockquote><p><code>PS C:\dev\appharbor\MyCoolApp&gt; git init<br />
PS C:\dev\appharbor\MyCoolApp&gt; git add .<br />
PS C:\dev\appharbor\MyCoolApp&gt; git commit -m "initial commit"</code></p></blockquote>
<p>And when this is done we add AppHarbor as a remote repository:</p>
<blockquote><p><code>PS C:\dev\appharbor\MyCoolApp&gt; git remote add appharbor https://moberg@appharbor.com/mycoolapp-1.git</code></p></blockquote>
<p>We are now set to push our code onto AppHarbor. To push it just type:</p>
<blockquote><p><code>PS C:\dev\appharbor\MyCoolApp&gt; git push appharbor master</code></p></blockquote>
<p>We should now be able to see the project building:</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/7.png"><img class="aligncenter size-full wp-image-1012" title="7" src="http://sourcecodebean.com/wp-content/uploads/2011/03/7.png" alt="" width="600" /></a></p>
<p>Hopefully it built successfully. A problem I ran into was that I had ASP.NET MVC 3 RC installed and AppHarbor had the RTM version installed, this caused my first attempt to build my project to fail. After upgrading my local version and fixing the project I pushed a new version that built without problems.</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/8.png"><img class="aligncenter size-full wp-image-1013" title="8" src="http://sourcecodebean.com/wp-content/uploads/2011/03/8.png" alt="" width="600" /></a></p>
<p>We can now browse to the site (yay! that was way easier than setting up IIS manually):</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/9.png"><img class="aligncenter size-full wp-image-1015" title="9" src="http://sourcecodebean.com/wp-content/uploads/2011/03/9.png" alt="" width="600" /></a></p>
<h3><strong>Failing tests</strong></h3>
<p>Ok, lets change something in our application that will make a test fail:</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/10.png"><img class="aligncenter size-full wp-image-1014" title="10" src="http://sourcecodebean.com/wp-content/uploads/2011/03/10.png" alt="" width="553" /></a></p>
<p>Now we are going to be bad and not run our unit tests before commiting and pushing the code</p>
<blockquote><p><code>PS C:\dev\appharbor\MyCoolApp&gt; git commit -a -m "a failing test"<br />
PS C:\dev\appharbor\MyCoolApp&gt; git push appharbor master</code></p></blockquote>
<p>.. and we are building again</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/11.png"><img class="aligncenter size-full wp-image-1016" title="11" src="http://sourcecodebean.com/wp-content/uploads/2011/03/11.png" alt="" width="600" /></a></p>
<p>Woot! The build has failed!</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/12.png"><img class="aligncenter size-full wp-image-1017" title="12" src="http://sourcecodebean.com/wp-content/uploads/2011/03/12.png" alt="" width="600" /></a></p>
<p>We can easily see that it is the test that verifies the text on the start page that has failed</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/13.png"><img class="aligncenter size-full wp-image-1018" title="13" src="http://sourcecodebean.com/wp-content/uploads/2011/03/13.png" alt="" width="600" /></a></p>
<p>Ok, lets fix it!</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/14small.png"><img class="aligncenter size-full wp-image-1020" title="14small" src="http://sourcecodebean.com/wp-content/uploads/2011/03/14small.png" alt="" height="212" /></a></p>
<p>Commit and push it again. And wait for the build to complete.</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/15.png"><img class="aligncenter size-full wp-image-1021" title="15" src="http://sourcecodebean.com/wp-content/uploads/2011/03/15.png" alt="" width="600" /></a></p>
<p>Yay! Our new version built successfully!</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/16.png"><img class="aligncenter size-full wp-image-1022" title="16" src="http://sourcecodebean.com/wp-content/uploads/2011/03/16.png" alt="" width="600" /></a></p>
<p>Lets check it out:</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/17.png"><img class="aligncenter size-full wp-image-1023" title="17" src="http://sourcecodebean.com/wp-content/uploads/2011/03/17.png" alt="" width="600" /></a></p>
<h3><strong>Rolling back to a previous version</strong></h3>
<p>Being able to rollback an update is sometimes necessary and AppHarbor makes it ridiculously simple, all you need to do is to press the &#8220;Deploy&#8221; link next to an old version. Clicking it will build and deploy the selected version.</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/18.png"><img class="aligncenter size-full wp-image-1024" title="18" src="http://sourcecodebean.com/wp-content/uploads/2011/03/18.png" alt="" width="600" /></a></p>
<p>We can now see that it is the first version that is active</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/19.png"><img class="aligncenter size-full wp-image-1025" title="19" src="http://sourcecodebean.com/wp-content/uploads/2011/03/19.png" alt="" width="600" /></a></p>
<p>I love the idea behind AppHarbor, this is really how sites should be deployed! However, using AppHarbor also means giving up some control over your environment. It will be interesting to see how they handle, for example, upgrades between different versions of IIS, installation of service packs, etc. Two features i miss is the ability to run background jobs and a distributed cache to use, but hopefully it will be coming to AppHarbor. AppHarbor still a very young startup, and so far what I have seen is really impressive!</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/appharbor-heroku-for-net/987/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: sourcecodebean.com @ 2012-05-30 06:15:41 -->
