<?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>Fri, 27 Jan 2012 20:36:28 +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>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><span id="more-1321"></span><br />
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? 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>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>2</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>
<p><span id="more-1211"></span></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. </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><span id="more-1161"></span><br />
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. 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>
		<item>
		<title>Running a website on Ubuntu 10.10 (Maverick) using Nginx and PHP-FastCGI</title>
		<link>http://sourcecodebean.com/archives/running-a-website-on-ubuntu-10-10-maverick-using-nginx-and-php-fastcgi/877</link>
		<comments>http://sourcecodebean.com/archives/running-a-website-on-ubuntu-10-10-maverick-using-nginx-and-php-fastcgi/877#comments</comments>
		<pubDate>Sun, 27 Feb 2011 14:14:09 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=877</guid>
		<description><![CDATA[Recently I decided to switch hosting provider from a shared server to a VPS. My choice of linux is Ubuntu so i installed the latest version, Ubuntu 10.10 server. Instead of using Apache as webserver, which has been my choice of webserver for years, I decided to go for Nginx. Nginx is known for its [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I decided to switch hosting provider from a shared server to a VPS. My choice of linux is Ubuntu so i installed the latest version, Ubuntu 10.10 server. Instead of using Apache as webserver, which has been my choice of webserver for years, I decided to go for Nginx. Nginx is known for its great performance, but what really caught my attention (and the main reason to why I picked it) is that it is so easy to install and configure.   </p>
<p><span id="more-877"></span></p>
<p><strong>Installing Nginx and configuring the site</strong><br />
The first step is to install the Nginx webserver and PHP. </p>
<blockquote><pre>apt-get install nginx php5-cli php5-cgi spawn-fcgi
update-rc.d nginx defaults
/etc/init.d/nginx start</pre>
</blockquote>
<p>Then we need to create the configuration for our site.<br />
<em>/etc/nginx/sites-enabled/sourcecodebean</em>:</p>
<blockquote>
<pre>
server {
        listen 80;
        server_name www.sourcecodebean.com;

        location / {
                rewrite ^/(.*) http://sourcecodebean.com/$1 permanent;
        }
}

server {
    listen   80;
    server_name sourcecodebean.com;

    index index.php;
    root /var/www/sourcecodebean.com/public_html;

    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:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/sourcecodebean.com/public_html$fastcgi_script_name;
    }
}
</pre>
</blockquote>
<p>The first server section is only there to redirect www.sourcecodebean.com to sourcecodebean.com. It would be nice if Nginx supported conditional location blocks, then this extra server block would not be needed. But from what I understand this is not supported.  </p>
<p>The second bock has two important parts</p>
<blockquote><pre>
    location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }
</pre>
</blockquote>
<p>This part handles the URL rewrite and is specific to WordPress. If don&#8217;t need URL rewrite you can leave this part out. </p>
<blockquote><pre>
 location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/sourcecodebean.com/public_html$fastcgi_script_name;
    }
</pre>
</blockquote>
<p>This section tells Nginx that all requests to files ending with .php should be routed to the PHP-FastCGI binary running on localhost. </p>
<p><strong>Configuring PHP-FastCGI</strong><br />
The second step is to get PHP-FastCGI working. First lets create a script to start it. Lets place it in <em>/usr/bin/php-fastcgi</em>. The script should contain the IP, port and what user the fastcgi process should run as. This is what my script looks like:</p>
<blockquote><pre>
  #!/bin/sh
  /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 6 -u www-data -f /usr/bin/php5-cgi
</pre>
</blockquote>
<p>The -C controls how many child processes that should be spawned. Make sure to make this script executable. </p>
<p>Now we need to configure so it automatically starts when the system starts. I found a simple init script in the linode library, so I am going to use that.</p>
<blockquote><pre>
wget https://library.linode.com/web-servers/nginx/php-fastcgi/reference/php-fastcgi-init-deb.sh
mv php-fastcgi-init-deb.sh /etc/init.d/php-fastcgi
chmod +x /etc/init.d/php-fastcgi
update-rc.d php-fastcgi defaults
/etc/init.d/php-fastcgi start
</pre>
</blockquote>
<p>Everything should now be up working. Lets test it by creating a simple php file, test.php, and placing it in your web root.</p>
<blockquote><pre>
&lt;?php phpinfo(); ?>
</pre>
</blockquote>
<p>Now browse http://<em>yourdomain.com</em>/test.php and hope that you get the phpinfo page!</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/running-a-website-on-ubuntu-10-10-maverick-using-nginx-and-php-fastcgi/877/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EPiServer – Continuous Integration and Deployment</title>
		<link>http://sourcecodebean.com/archives/episerver-%e2%80%93-continuous-integration-and-deployment/716</link>
		<comments>http://sourcecodebean.com/archives/episerver-%e2%80%93-continuous-integration-and-deployment/716#comments</comments>
		<pubDate>Tue, 30 Nov 2010 08:28:06 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=716</guid>
		<description><![CDATA[Two weeks ago I went to the EPiServer Meetup where Bartek Tatkowski talked about EPiServer and CI. This got me inspired to write about how we do CI and deployment in my current project. The site we are building is an EPiServer 6 CMS Enterprise site based on .NET 4.0 and ASP.NET MVC 2.0 (I [...]]]></description>
			<content:encoded><![CDATA[<p>Two weeks ago I went to the <a href="http://www.meetup.com/EPiServer-Stockholm/calendar/15377221/">EPiServer Meetup </a>where <a href="http://twitter.com/tatkowski">Bartek Tatkowski</a> talked about EPiServer and CI. This got me inspired to write about how we do CI and deployment in my current project. The site we are building is an EPiServer 6 CMS Enterprise site based on .NET 4.0 and ASP.NET MVC 2.0 (<a href="http://sourcecodebean.com/archives/first-steps-toward-episerver-and-asp-net-mvc/595">I blogged about it back in Apri</a>l). When we started the project we had very clear goals regarding CI and deployment:</p>
<ul>
<li>The build process should be totally automated</li>
<li>Building the site should result in a release package</li>
<li>The build server should run unit tests, code analysis and test code coverage every time the build is run</li>
<li>The deployment process should be totally automatic (for the test environment and for the production environment)</li>
<li>It should always be possible to rollback an update (files, database, IIS-settings, etc.). Rollback should also be fully automated.</li>
</ul>
<p>I am very happy to say that we have fulfilled all our above goals, let me tell you have we did it.<br />
<span id="more-716"></span></p>
<h2>Build process and the release package</h2>
<p>We are using TeamCity as build server. TeamCity is great build server which support numerous different build agents and it hooks up very easily with our Mercurial version control system. This is what a typical check in/build/package scenario looks like:</p>
<ol>
<li>1. A developer checks in new code</li>
<li>2. TeamCity picks up the change from Mercurial and starts a build</li>
<li>3. Once built TeamCity runs all the units tests, code analysis and code coverage</li>
<li>4. If the unit tests are successful the TeamCity creates a deploy package. The package contains a MSDeploy zip file, configuration files and our deploy tool chain (Powershell scripts and a few executables) – everything you need to deploy the site.</li>
</ol>
<p>By downloading and extracting this file you get a file structure that looks like this:</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2010/11/release-package.png"><img class="aligncenter size-full wp-image-721" title="release-package" src="http://sourcecodebean.com/wp-content/uploads/2010/11/release-package.png" alt="" width="208" height="212" /></a></p>
<p><strong>Scripts</strong> – contains various scripts needed to perform deployment, the most important being <code>Deploy.ps1</code> and <code>Deploy-Local.ps1</code>.</p>
<p><strong>SiteConfig</strong> – contains shared settings and one directory per unique environment (AT = Acceptance Test, ST = System Test, Dev-PM = My development environment). In the SiteConfig directory we also find the following files:</p>
<ul>
<li>settings.xml</li>
<li>episerver-config.master.xml</li>
<li>episerver-config-site1.xml</li>
<li>episerver-config-site2.xml</li>
</ul>
<p>The <code>settings.xml</code> is the base of all non-episerver settings. It contains connection strings to databases, paths to where the web site should be installed, where logs should be placed, where VPP files are placed, integration settings to external systems and much more.</p>
<p>In each environment specific directory, such as “AT” it is possible to override these settings by creating a <code>settings.xml</code>. The new <code>settings.xml</code> does not replace the one in the parent directory, it is merged with it and the environment specific file takes precedence over the general.</p>
<p>A simple example let pretend this is our <code>\SiteSettings\settings.xml</code>:</p>
<p><code>&lt;settings&gt;<br />
&nbsp;&nbsp;&lt;webDir&gt;D:\WebSites\&lt;/webDir&gt;<br />
&nbsp;&nbsp;&lt;logDir&gt;D:\Logs&lt;/logDir&gt;<br />
&lt;/settings&gt;</code></p>
<p>Say that I would like to override where the logs are stored in my ST environment. To do this I would create <code>\SiteSettings\ST\settings.xml</code>, containing:</p>
<p><code>&lt;settings&gt;<br />
&nbsp;&nbsp;&lt;logDir&gt;C:\Temp\Logs&lt;/logDir&gt;<br />
&lt;/settings&gt;</code></p>
<p>The merged config would be:</p>
<p><code>&lt;settings&gt;<br />
&nbsp;&nbsp;&lt;webDir&gt;D:\WebSites\&lt;/webDir&gt;<br />
&nbsp;&nbsp;&lt;logDir&gt;C:\Temp\Logs&lt;/logDir&gt;<br />
&lt;/settings&gt;</code></p>
<p>We use this for both development and deployment. When a developer checks out the source code, there is a “<code>Init.ps1</code>” script in the Scripts folder (not included in the release package). This script will setup the website according to the specified settings (in my case the Dev-PM folder). The script configures the local IIS server, creates app pools,  creates the sites, sets permissions on folders, creates local MSMQ queues, configures NServiceBus and so on. Thanks to this script all the developers have a development environment that is nearly identical! Super sweet!</p>
<p>Ok, back to deployment. As you might have figured out, the <code>episerver-config.master.xml</code> serves as base for all episerver sites. Since this is an enterprise installation we can have several sites and each –siteX represents such a site.</p>
<p>All the settings in the files are overridable in the same way as with <code>settings.xml</code>. We use this to, for example, provide the appropriate license file for the specific environment. </p>
<p><strong>SiteWebDeployPackage</strong></p>
<p>This might be the least exciting directory, it simply contains a MS WebDeploy package created by MSBuild. This package contains everything needed to run the sites, except for the site specific configuration files that <code>Deploy.ps1/Deploy-Local.ps1</code> will put in place.</p>
<p><strong>Tools<br />
</strong>This directory contains our “deploy tool chain”. The tool chain includes, MSDeploy.exe (WebDeploy), SimpleScriptRunner.exe (DB migration), 7za.exe (zip) and a bunch of other tools needed to setup and install Msmq and NserviceBus.</p>
<h2>The deploy process</h2>
<p>When we started implementing the automated deployment we were hoping to be able to do most of the heavy lifting in WebDeploy. But after a lot of research and testing we came to the conslusion that it was probably possible to do what we wanted to do in WebDeploy (WebDeploy is very powerfull), but we could not figure out how. The WebDeploy documentation at that time was almost non-existent and had few advanced examples. Instead we made the decision to use PowerShell for most of the work and use WebDeploy only as a method to package transfer files. </p>
<p>This is the steps needed to perform a deployment:</p>
<ol>
<li>1. Download the latest release package from TeamCity</li>
<li>2. Extract it, start PowerShell and cd into the Scripts folder</li>
<li>3. Run &#8220;Deploy.ps1 &lt;environment&gt;&#8221;. The addresses of the servers are confgured in the environment settings</li>
</ol>
<p>This is what Deploy.ps1 does:</p>
<ol>
<li>1. Remotes to the service bus host and takes it offline</li>
<li>2. Remotes to the webserver and takes the site offline</li>
<li>3. Creates a backup of the entire IIS containing all its settings and sites using WebDeploy (used if rollback is carried out)</li>
<li>4. Creates a backup of all databases (used for rollback)</li>
<li>5. Uses SimpleScriptRunner to connect to our database server and apply database schema updates on our databases (not the EPiServer database)</li>
<li>6. Copies the deploy package to the webserver</li>
<li>7. Remotes to the webserver and runs <code>Deploy-Local.ps1</code>. The script installs the files, configures IIS, copies license files, etc.</li>
<li>8. Starts the site and the service bus and runs runs integration tests</li>
<li>9. Print result and exit!</li>
</ol>
<p>If the update of some reason is not working as it should, the update can be easily rolled back by executing  &#8220;Deploy.ps1 &lt;environment&gt; -Rollback&#8221;. This will restore all affected system to exactly the same point as they were before the update.</p>
<p><strong><br />
</strong></p>
<h2>Conclusion</h2>
<p>Automating the build and the deployment process is absolutly worth the effort it takes to implement it. By automating the process we have been able to catch more bugs, develop and release faster and at the same time make the entire process less dependent on certain people in the group &#8211; our knowledge is documented in the build and deployment scripts.</p>
<p>A very nice bonus from this is that we can version control everything related to the site, IIS settings, EPiServer settings, EPiServer Licenses and much more. Also, installing the release on a &#8220;empty&#8221; server is as easy as updating an existing installation.<br />
<br/></p>
<p><strong>The tools that made all this possible:</strong></p>
<p>Microsoft <a href="http://www.iis.net/download/webdeploy">WebDeploy</a> &#8211; Deployment tool from Microsoft.</p>
<p><a href="https://github.com/JamesKovacs/psake">Psake</a>- Build automation tool written in PowerShell (inspired by rake in Ruby).</p>
<p><a href="http://code.google.com/p/simplescriptrunner/">SimpleScriptRunner </a>- Tool to run a directory of numbered sql scripts against an MSSQL database.</p>
<p><a href="http://opendbiff.codeplex.com/">OpenDBDiff </a>- Tool/library to generate SQL-diff scripts.</p>
<p><a href="http://pagetypebuilder.codeplex.com/">PageTypeBuilder</a> &#8211; Automatic synchronization of pagetypes in EPiServer (page types are defined in code)</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/episerver-%e2%80%93-continuous-integration-and-deployment/716/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Synchronizing files and executing commands on a remote server using MSDeploy</title>
		<link>http://sourcecodebean.com/archives/synchronizing-files-and-executing-commands-on-a-remote-server-using-msdeploy/775</link>
		<comments>http://sourcecodebean.com/archives/synchronizing-files-and-executing-commands-on-a-remote-server-using-msdeploy/775#comments</comments>
		<pubDate>Sun, 21 Nov 2010 22:03:31 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=775</guid>
		<description><![CDATA[Microsoft WebDeploy (MSDeploy) is a very useful tool, not only for deploying web sites. In this post I will show you how MSDeploy can be used as a tool for synchronizing local and remote folders and executing commands on a remote server. The first thing you need to do is to install WebDeploy. It can [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft WebDeploy (MSDeploy) is a very useful tool, not only for deploying web sites. In this post I will show you how MSDeploy can be used as a tool for synchronizing local and remote folders and executing commands on a remote server. </p>
<p><span id="more-775"></span><br />
The first thing you need to do is to install WebDeploy. It can be installed using Web Platform Installer or by downloading the .msi file. I prefer to download the .msi. It can be found <a href="http://www.iis.net/download/webdeploy">here</a>. Download the installer and run this (you can change the port and the address to whatever you want):</p>
<blockquote><p><code>msiexec /I WebDeploy_x64_en-US.msi /passive ADDLOCAL=ALL LISTENURL=http://+:80/MsDeployAgentService/<br />
</code></p></blockquote>
<p>Then start the service:</p>
<blockquote><p><code>net start msdepsvc</code></p></blockquote>
<p>To check if the service is up running execute:</p>
<blockquote><p><code><br />
c:\program files\iis\microsoft web deploy\msdeploy.exe -verb:sync<br />
        -source:dirPath='d:\some\local\path'<br />
        -dest:dirPath='f:\some\remote\path',<br />
               computerName=http://xxx.xxx.xxx.xxx:1234/MSDeploy,<br />
            userName=remoteUser,password=remotePassword -verbose<br />
</code></p></blockquote>
<p>If the service is up running a lot of information will be printed to the screen, if not, MSDeploy will complain on that the remote service did not respond with &#8220;v1&#8243; of MSDeploy.</p>
<p><br/></p>
<h2>The sync script</h2>
<p>Bellow is a simple PowerShell script that has two functions. </p>
<p><strong>Send-Files</strong> &#8211; Synchronizes a local folder to a remote server.</p>
<p><strong>Execute-RemoteCommand </strong> &#8211; Executes a batch file on a remote server. The file must already be in place on the server.</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">$MSDeployExe = <span class="st0">&quot;C:<span class="es0">\P</span>rogram Files<span class="es0">\I</span>IS<span class="es0">\M</span>icrosoft Web Deploy<span class="es0">\m</span>sdeploy.exe&quot;</span></div>
</li>
<li class="li1">
<div class="de1">$RemoteHost = <span class="st0">&quot;http://localhost:80/MsDeployAgentService&quot;</span></div>
</li>
<li class="li1">
<div class="de1">$Credentials = <span class="st0">&quot;&quot;</span></div>
</li>
<li class="li2">
<div class="de2">$LocalDir = <span class="st0">&quot;C:<span class="es0">\t</span>emp<span class="es0">\L</span>ocalDir&quot;</span></div>
</li>
<li class="li1">
<div class="de1">$RemoteDir = <span class="st0">&quot;C:<span class="es0">\t</span>emp<span class="es0">\R</span>emoteDir&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">function Send-Files <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; param <span class="br0">&#40;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span><span class="kw3">string</span><span class="br0">&#93;</span>$WebDeployService,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span><span class="kw3">string</span><span class="br0">&#93;</span>$LocalDir,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span><span class="kw3">string</span><span class="br0">&#93;</span>$RemoteDir,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span><span class="kw3">string</span><span class="br0">&#93;</span>$Credentials</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <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; Write-Host <span class="st0">&quot;Sending files to $WebDeployService`: $RemoteDir&quot;</span> -ForegroundColor Yellow</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>$Credentials -ne <span class="st0">&quot;&quot;</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; $Credentials = <span class="st0">&quot;,getCredentials=&quot;</span> + $Credentials</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;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &amp; $MSDeployExe <span class="st0">&quot;-verb:sync&quot;</span> <span class="st0">&quot;-source:dirPath=$LocalDir&quot;</span> <span class="st0">&quot;-dest:dirPath=$RemoteDir,computername=$WebDeployService$Credentials&quot;</span> <span class="st0">&quot;-verbose&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; $successful = $?</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>-<span class="kw1">not</span> $successful<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; throw <span class="st0">&quot;Failed sending files&quot;</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"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">function Execute-RemoteCommand <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; param <span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span><span class="kw3">string</span><span class="br0">&#93;</span>$WebDeployService,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span><span class="kw3">string</span><span class="br0">&#93;</span>$RemoteDir,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span><span class="kw3">string</span><span class="br0">&#93;</span>$BatchFile,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span><span class="kw3">string</span><span class="br0">&#93;</span>$Credentials,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span><span class="kw2">int</span><span class="br0">&#93;</span>$waitInterval = <span class="nu0">15000</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; $command = Join-Path $RemoteDir $BatchFile</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; Write-Host <span class="st0">&quot;Executing $command on $WebDeployService&quot;</span> -ForegroundColor Yellow</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &amp; $MSDeployExe <span class="st0">&quot;-verb:sync&quot;</span> <span class="st0">&quot;-source:runCommand=&#8217;$command&#8217;,waitInterval=$waitInterval,waitAttempts=1&quot;</span> <span class="st0">&quot;-dest:auto,computername=$RemoteHost$Credentials&quot;</span> <span class="st0">&quot;-verbose&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; $successful = $?</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>-<span class="kw1">not</span> $successful<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; throw <span class="st0">&quot;Failed executing command&quot;</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"><span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># Test </span></div>
</li>
<li class="li1">
<div class="de1">Send-Files $RemoteHost $LocalDir $RemoteDir $Credentials</div>
</li>
<li class="li1">
<div class="de1">Execute-RemoteCommand $RemoteHost $RemoteDir <span class="st0">&quot;HelloWorld.bat&quot;</span> $Credentials</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/synchronizing-files-and-executing-commands-on-a-remote-server-using-msdeploy/775/feed</wfw:commentRss>
		<slash:comments>0</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-02-06 06:30:57 -->
