<?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>Kevin Grad</title>
	<atom:link href="http://couchware.ca/www/kev/feed/" rel="self" type="application/rss+xml" />
	<link>http://couchware.ca/www/kev</link>
	<description>Designer, Programmer and Co-Founder</description>
	<lastBuildDate>Sat, 05 Feb 2011 20:51:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Coding a web server with C# &#8211; part 2</title>
		<link>http://couchware.ca/www/kev/2011/02/05/coding-a-web-server-with-c-part-2/</link>
		<comments>http://couchware.ca/www/kev/2011/02/05/coding-a-web-server-with-c-part-2/#comments</comments>
		<pubDate>Sat, 05 Feb 2011 20:48:11 +0000</pubDate>
		<dc:creator>kev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[web-server]]></category>

		<guid isPermaLink="false">http://couchware.ca/www/kev/?p=269</guid>
		<description><![CDATA[Hey all,
We left off at the end of my last article being able to grab and print a GET request from a web page. There were a few issues with the way we did things however. Firstly, we were reading in a buffer the size of the maximum possible buffer size, so when we were [...]]]></description>
			<content:encoded><![CDATA[<p>Hey all,</p>
<p>We left off at the end of my last article being able to grab and print a GET request from a web page. There were a few issues with the way we did things however. Firstly, we were reading in a buffer the size of the maximum possible buffer size, so when we were printing out our request it was followed by a ton of whitespace. In order to fix this I tried to trim the string for whitespace, this did not work.<br />
<span id="more-269"></span></p>
<p>It turns out that if you take a look at the ASCII characters of the string you get in the byte buffer you will notice that there are a ton of 0&#8217;s at the end of the string. This corresponds to the null character. When Receive() grabs data from the socket, it will fill up the remainder of the array with null characters, so to trim the string we simply use</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:Consolas, monospace;">    convertedData <span style="color: #008000;">=</span> convertedData.<span style="color: #0000FF;">Trim</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">'<span style="color: #008080; font-weight: bold;">\0</span>'</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Our next issue is how to parse the request we get. Basically all we want to do is find out what page/resource they are looking for and then check to see if that page exists, if it does respond with it, otherwise respond with nothing. However, there is a special case we have to look for. When a person browses to a site like www.blah.com the first get request is always going to look like &#8220;GET / http/1.1&#8243;, followed by the rest of the GET request. What this means is that the browser is looking for the &#8220;/&#8221; file or resource. By convention this &#8220;/&#8221; is always index.html (unless otherwise defined) so we have to check for this in our server. </p>
<p>So I created a method to parse our get that just looks at the first line of the request and returns the proper resource.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:Consolas, monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> ParseGet<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span> getRequest<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Set the directory to server from to desktop\sites.</span>
    var path <span style="color: #008000;">=</span> Environment.<span style="color: #0000FF;">GetFolderPath</span><span style="color: #000000;">&#40;</span>Environment.<span style="color: #0000FF;">SpecialFolder</span>.<span style="color: #0000FF;">DesktopDirectory</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\\</span>sites&quot;</span><span style="color: #008000;">;</span>
    var words <span style="color: #008000;">=</span> getRequest.<span style="color: #0000FF;">Split</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>words<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Equals</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;GET&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>words<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Equals</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;/&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">return</span> <span style="color: #008000;">!</span>File.<span style="color: #0000FF;">Exists</span><span style="color: #000000;">&#40;</span>path <span style="color: #008000;">+</span> words<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">?</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">:</span> File.<span style="color: #0000FF;">ReadAllBytes</span><span style="color: #000000;">&#40;</span>path <span style="color: #008000;">+</span> words<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">else</span>
    <span style="color: #000000;">&#123;</span>
        var bytes <span style="color: #008000;">=</span> File.<span style="color: #0000FF;">ReadAllBytes</span><span style="color: #000000;">&#40;</span>path<span style="color: #008000;">+</span><span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\\</span>index.html&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">return</span> bytes<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Our final problem is that currently, we can only accept one request at a time. We listen on the port until a request is made, then we process that request until completion, then we listen again. We want to be able to handle multiple requests concurrently, so we must thread our request procession. To do this, we move our request processing out into its own method:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:Consolas, monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> ProcessRequest<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">Object</span> o<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    var acceptedSocket <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>Socket<span style="color: #000000;">&#41;</span> o<span style="color: #008000;">;</span>
    <span style="color: #008080; font-style: italic;">// Read request.</span>
    var data <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span>acceptedSocket.<span style="color: #0000FF;">ReceiveBufferSize</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
    acceptedSocket.<span style="color: #0000FF;">Receive</span><span style="color: #000000;">&#40;</span>data<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    var convertedData <span style="color: #008000;">=</span> Encoding.<span style="color: #0000FF;">ASCII</span>.<span style="color: #0000FF;">GetString</span><span style="color: #000000;">&#40;</span>data<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Receive() fills the buffer with nulls after the data has been read.</span>
    convertedData <span style="color: #008000;">=</span> convertedData.<span style="color: #0000FF;">Trim</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">'<span style="color: #008080; font-weight: bold;">\0</span>'</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #FF0000;">char</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> delimiters <span style="color: #008000;">=</span> <span style="color: #000000;">&#123;</span> <span style="color: #666666;">'<span style="color: #008080; font-weight: bold;">\r</span>'</span>, <span style="color: #666666;">'<span style="color: #008080; font-weight: bold;">\n</span>'</span> <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
    var lines <span style="color: #008000;">=</span> convertedData.<span style="color: #0000FF;">Split</span><span style="color: #000000;">&#40;</span>delimiters, StringSplitOptions.<span style="color: #0000FF;">RemoveEmptyEntries</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;{0}&quot;</span>, convertedData<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    var outData <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Write response.</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Make sure there is data to parse.</span>
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span> <span style="color: #008000;">!=</span> lines.<span style="color: #0000FF;">Length</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        outData <span style="color: #008000;">=</span> ParseGet<span style="color: #000000;">&#40;</span>lines<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    acceptedSocket.<span style="color: #0000FF;">Send</span><span style="color: #000000;">&#40;</span>outData<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    acceptedSocket.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>You will notice from the above code that ProcessRequest takes an Object instead of a socket. This is too bad, it would be nice if you could do that<br />
ParameterizedThreadStart requires a method that takes an object and I could find no way around this.</p>
<p>Our final run method now looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:Consolas, monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Run<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Set up socket for listening.</span>
    var hostIp <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>Dns.<span style="color: #0000FF;">GetHostAddresses</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;127.0.0.1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Listening on {0}:{1}&quot;</span>, hostIp, Port<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    var endPoint <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> IPEndPoint<span style="color: #000000;">&#40;</span>hostIp, Port<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    TcpSocket.<span style="color: #0000FF;">Bind</span><span style="color: #000000;">&#40;</span>endPoint<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        TcpSocket.<span style="color: #0000FF;">Listen</span><span style="color: #000000;">&#40;</span>BackLog<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        var processThread <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Thread<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> ParameterizedThreadStart<span style="color: #000000;">&#40;</span>ProcessRequest<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        processThread.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span>TcpSocket.<span style="color: #0000FF;">Accept</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>If you create a directory on your desktop, place an index.html in there and then navigate to http://127.0.0.1 it will now<br />
serve your very own index.html. Here is mine:<br />
<img src="http://couchware.ca/users/kevin/index.png" alt="Index!" /><br />
If you would like to check out the code, it is available here: <a href="http://code.google.com/p/kevserver/">KevServer</a></p>
]]></content:encoded>
			<wfw:commentRss>http://couchware.ca/www/kev/2011/02/05/coding-a-web-server-with-c-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coding a web server with C# &#8211; part 1</title>
		<link>http://couchware.ca/www/kev/2011/02/01/coding-a-web-server-with-c-part-1/</link>
		<comments>http://couchware.ca/www/kev/2011/02/01/coding-a-web-server-with-c-part-1/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 02:30:54 +0000</pubDate>
		<dc:creator>kev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[web-server]]></category>

		<guid isPermaLink="false">http://couchware.ca/www/kev/?p=220</guid>
		<description><![CDATA[Howdy folks,
It has been quite a while since I programmed something productive on my own time. I have been really busy lately at work as we are finishing up our major project from the last 6 months. Hopefully at some point I will write a blog post regarding that project as it is really interesting. [...]]]></description>
			<content:encoded><![CDATA[<p>Howdy folks,</p>
<p>It has been quite a while since I programmed something productive on my own time. I have been really busy lately at work as we are finishing up our major project from the last 6 months. Hopefully at some point I will write a blog post regarding that project as it is really interesting. I have also been reading up on some languages I have toyed around with (Javascript, Objective-C, C#, Clojure). I also haven&#8217;t updated this blog in months. Because of these facts I have decided that it is time to stop reading and start doing, so I have come up with a fun little project for myself.<br />
<span id="more-220"></span></p>
<p>Yesterday I was in my idea chamber (shower) and I came up with a fun little idea that shouldn&#8217;t be too hard and will teach me a bit about two subjects I would like to know more about. I have decided to write my own little web server from scratch using C#. This will teach me more about C# and its libraries as well a lot more about the HTTP/1.1 protocol.</p>
<p>Now I know that C# comes with some nice libraries that makes writing things like web servers pretty easy/trivial, so I have decided not to use any of them. I will not be using HTTPWebRequest or HTTPWebResponse. I will be doing this using straight sockets and a design from my own head, as well as a lot of help from MSDN and the HTTP spec.</p>
<p>The second part of this journey will be to blog about my exploits so you guys can critique, offer suggestions, bash my designs or praise my awesomeness. This way I can actually tackle three birds with one stone as in addition to learning C# and HTTP I will practice my writing by blogging about it. So without further ado I will take you through my initial steps. If anyone is interested all my code is available at <a href="http://code.google.com/p/kevserver">Google Code</a> and will be updated as I go.</p>
<p>The first step I set out to achieve is to create a socket that will listen to a single request on a specific port, pretty basic. However, being a C# beginner I had no idea what to do, so I did what any competent programmer would do, I Googled &#8220;C# sockets&#8221; as well as &#8220;Http&#8221; and some other related stuff. I quickly came upon the MSDN article on the Socket class located in System.Net.Sockets.</p>
<p>As an aside, I have to say, this is the first time I have ever used MSDN and it is pretty damn good. Not only does it give you the full API for whatever you are looking for, it also provides you with code snippets on how to use it! INVALUABLE! Much much better resource than the JavaDocs I am used to. I guess that is what you get when you have professional support for your API&#8230; I would probably still prefer the API to be open source but I digress. Anyway, I quickly found what I was looking for (Socket) and set to work. After about an hour of mucking about I finally achieved some code that actually works and displayed a single get request from my browser. Behold my work of art:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:Consolas, monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Net</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Net.Sockets</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> KevServer
<span style="color: #000000;">&#123;</span>
    <span style="color: #FF0000;">class</span> Server
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">int</span> Port <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">private</span> Socket TcpSocket <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">int</span> BackLog <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> Server<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            TcpSocket <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Socket<span style="color: #000000;">&#40;</span>AddressFamily.<span style="color: #0000FF;">InterNetwork</span>,
                SocketType.<span style="color: #0000FF;">Stream</span>, ProtocolType.<span style="color: #0000FF;">Tcp</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Port <span style="color: #008000;">=</span> <span style="color: #FF0000;">8080</span><span style="color: #008000;">;</span>
            BackLog <span style="color: #008000;">=</span> <span style="color: #FF0000;">5</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Run<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var hostIp <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>Dns.<span style="color: #0000FF;">GetHostAddresses</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;127.0.0.1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Listening on {0}:{1}&quot;</span>, hostIp, Port<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            var endPoint <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> IPEndPoint<span style="color: #000000;">&#40;</span>hostIp, Port<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            TcpSocket.<span style="color: #0000FF;">Bind</span><span style="color: #000000;">&#40;</span>endPoint<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            TcpSocket.<span style="color: #0000FF;">Listen</span><span style="color: #000000;">&#40;</span>BackLog<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            var acceptedSocket <span style="color: #008000;">=</span> TcpSocket.<span style="color: #0000FF;">Accept</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            var data <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span>acceptedSocket.<span style="color: #0000FF;">ReceiveBufferSize</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
            acceptedSocket.<span style="color: #0000FF;">Receive</span><span style="color: #000000;">&#40;</span>data, <span style="color: #FF0000;">0</span>,
                acceptedSocket.<span style="color: #0000FF;">ReceiveBufferSize</span>, SocketFlags.<span style="color: #0000FF;">None</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            var convertedData <span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span>.<span style="color: #0000FF;">Encoding</span>.<span style="color: #0000FF;">ASCII</span>.<span style="color: #0000FF;">GetString</span><span style="color: #000000;">&#40;</span>data<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;{0}&quot;</span>, convertedData<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Console.<span style="color: #0000FF;">Read</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>When opening up my browser and pointing it to 127.0.0.1:8080 my console printed the following:<br />
<img src="http://couchware.ca/users/kevin/get-request.png" alt="GET!" /></p>
<p>Great Success! First hurdle achieved, next step: parsing the request and returning a page.<br />
More to come, stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://couchware.ca/www/kev/2011/02/01/coding-a-web-server-with-c-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unsure whether or not I am caving</title>
		<link>http://couchware.ca/www/kev/2010/04/16/i-can-no-longer-support-apple/</link>
		<comments>http://couchware.ca/www/kev/2010/04/16/i-can-no-longer-support-apple/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 17:43:53 +0000</pubDate>
		<dc:creator>kev</dc:creator>
				<category><![CDATA[Stuff]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[macbook]]></category>

		<guid isPermaLink="false">http://couchware.ca/www/kev/?p=198</guid>
		<description><![CDATA[I have waited a long time for the new MacBook Pros to be released, and finally that wait is over. The other day Apple released their refreshed MacBook pro line with shiny new core i5 and i5 processors. However, they also released their new terms of service for iPad/iPhone development. If you are a developer [...]]]></description>
			<content:encoded><![CDATA[<p>I have waited a long time for the new MacBook Pros to be released, and finally that wait is over. The other day Apple released their refreshed MacBook pro line with shiny new core i5 and i5 processors. However, they also released their new terms of service for iPad/iPhone development. If you are a developer and have not heard about this yet, you must be living under a rock (or not care about Apple in the slightest).</p>
<p><span id="more-198"></span></p>
<p>Basically Apple has decided that you can only program for apple using Apple approved programming languages and apple approved tools. The TOS states:</p>
<blockquote><p>
Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs. Applications must be originally written in Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine, and only code written in C, C++, and Objective-C may compile and directly link against the Documented APIs.</p></blockquote>
<p>This implies that applications that link to Documented APIs through an intermediary translation or compatibility layer or tool are prohibited, such as MonoTouch or Adobe&#8217;s new CS5 flash-to-iPhone conversion tool. A Google search of &#8220;Apple TOS 3.3.1&#8243; will give more insight into the implications of this statement and what I am writing about. Apple already has the most locked down operating system and platforms (no Flash/Java) and now want to control how developers develop for those platforms (can only program for platforms in specific languages Apple approves&#8230; codswallop). </p>
<p>edit: I am going back and forth on the issue. Making no claims anymore.</p>
]]></content:encoded>
			<wfw:commentRss>http://couchware.ca/www/kev/2010/04/16/i-can-no-longer-support-apple/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update: Wezzle, JavaEE 6 and beyond</title>
		<link>http://couchware.ca/www/kev/2010/03/01/update-wezzle-javaee6-and-beyond/</link>
		<comments>http://couchware.ca/www/kev/2010/03/01/update-wezzle-javaee6-and-beyond/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 21:13:59 +0000</pubDate>
		<dc:creator>kev</dc:creator>
				<category><![CDATA[Stuff]]></category>
		<category><![CDATA[ejb]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[Wezzle]]></category>

		<guid isPermaLink="false">http://couchware.ca/www/kev/?p=171</guid>
		<description><![CDATA[Greetings Earthlings. 
It has come to my attention that I have not updated this blog in quite a while. This is an error that I wish to remedy immediately. Since my last post a lot of fun and exciting things have happened and I have learned a ton of new stuff that I will hopefully [...]]]></description>
			<content:encoded><![CDATA[<p>Greetings Earthlings. </p>
<p>It has come to my attention that I have not updated this blog in quite a while. This is an error that I wish to remedy immediately. Since my last post a lot of fun and exciting things have happened and I have learned a ton of new stuff that I will hopefully write about in the near future.<br />
<span id="more-171"></span><br />
I would like to announce that <a href="http://couchware.ca/www/wezzle/">Wezzle </a>has been completed and is for sale on our website! It only took two years since Couchware&#8217;s inception, but it&#8217;s finally here and it looks great. I couldn&#8217;t be happier with the way Wezzle turned out. I think it looks outstanding and has some enjoyable and addicting game play. </p>
<p>I would like to give a huge thanks to those who assisted in the creation of the Wezzle. This includes Renee and Sam and all of our testers. If you like the art and music in the game be sure to check out <a href="http://www.reneelung.ca">Renee&#8217;s </a>and <a href="http://www.soundclick.com/bands/default.cfm?bandID=146918">Sam&#8217;s</a> websites. </p>
<p>Despite having put the game up for sale, Wezzle is not yet 100% complete. We are still hard at work finishing up a Wezzle demo that will be playable within the browser. Once the demo has been completed, we will be marketing/launching the game to a larger audience (hopefully!). There will likely be a launch party at an as of yet undisclosed location in Toronto. For those interested in coming, fire me an email or check back at this blog occasionally. Cam has also been hard at work at a REALLY cool Wezzle port, the nature of which I can&#8217;t disclose at the moment. It will be hopefully laying the ground-work for some of our future projects.</p>
<p>In other news, I have been put in charge of a major project using Java EE 6 which I&#8217;m pretty excited about.  Some of the technologies I have been using lately include: <a href="http://maven.apache.org/">Maven2</a>, <a href="http://logback.qos.ch/">Logback</a>, <a href="http://java.sun.com/developer/technicalArticles/J2EE/jpa/">JPA</a>/<a href="http://www.hibernate.org">Hibernate</a>, <a href="https://javaserverfaces.dev.java.net/">JSF</a>, <a href="http://java.sun.com/products/ejb/index.jsp">EJB 3.1</a>, and more. Hopefully in the coming weeks I will have something interesting to say about some of these. </p>
<p>Finally, I have bought kevingrad.com, org and net (all currently have no content) and I will eventually be moving this blog to one of those (probably .org).</p>
]]></content:encoded>
			<wfw:commentRss>http://couchware.ca/www/kev/2010/03/01/update-wezzle-javaee6-and-beyond/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comment from today&#8217;s code.</title>
		<link>http://couchware.ca/www/kev/2009/09/24/comment-from-todays-code/</link>
		<comments>http://couchware.ca/www/kev/2009/09/24/comment-from-todays-code/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 01:39:53 +0000</pubDate>
		<dc:creator>kev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Wezzle]]></category>
		<category><![CDATA[comment]]></category>
		<category><![CDATA[lwjgl]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/kev/?p=165</guid>
		<description><![CDATA[

// WARNING: the ctrl mask randomly subtracts 96 from the ascii
// of any character returned from getEventCharacter(). This is because
// LWJGL is fucked. We had a 30 min convo about this and decided
// to fuck the ctrl key. Alt is better.

]]></description>
			<content:encoded><![CDATA[<pre>

// WARNING: the ctrl mask randomly subtracts 96 from the ascii
// of any character returned from getEventCharacter(). This is because
// LWJGL is fucked. We had a 30 min convo about this and decided
// to fuck the ctrl key. Alt is better.
</pre>
]]></content:encoded>
			<wfw:commentRss>http://couchware.ca/www/kev/2009/09/24/comment-from-todays-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wezzle Test 7 is out!</title>
		<link>http://couchware.ca/www/kev/2009/06/17/wezzle-test-7-is-out/</link>
		<comments>http://couchware.ca/www/kev/2009/06/17/wezzle-test-7-is-out/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 16:32:17 +0000</pubDate>
		<dc:creator>kev</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Wezzle]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/kev/?p=163</guid>
		<description><![CDATA[Well, It has been a little while since we have posted anything new about Wezzle. Both Cam and myself have been pretty busy with other endeavors and progress on Wezzle slowed quite a bit. But now we are back to working on it and even though I got hit with a bout of the swine [...]]]></description>
			<content:encoded><![CDATA[<p>Well, It has been a little while since we have posted anything new about Wezzle. Both Cam and myself have been pretty busy with other endeavors and progress on Wezzle slowed quite a bit. But now we are back to working on it and even though I got hit with a bout of the swine flu, we managed to release Wezzle test 7!</p>
<p><span id="more-163"></span></p>
<p>Test 7 add a ton on top of test 6. This is copied from our official post in our forums:</p>
<ul>
<li>  An updated Play Now menu that has a look consistent across all menues.</li>
<li> Added achievements.</li>
<li> An achievements browser, that allows you to scroll through all achievements in the game and to see which ones you have done, and when.</li>
<li> An in-game achievement notification. In fact, we’ve added a general notification system that will give you tips and other information as the game progresses (these can be turned off, of course).</i>
<li> Improved line sounds. As you get more and more line chains, the line sound increases by a semi-tone. It’s quite exciting.</li>
<li> An improved tile dropping algorithm. You now get fewer random drop-in lines, so that the game no longer feels like it plays itself.</li>
<li> An improved, peripheral timer. When you get up to level 10 like the big boys, you need to have a better idea of how much time you have. Our new timer does just that.</li>
<li> An Options Menu.</li>
<li> The ability to turn off tutorials (once you&#8217;ve played them once of course!)</li>
<li> An new, more intuitive music selector.</li>
<li> A piece previewer (up in the top corner) as well as an overlayed piece previewer (check the Options Menu from the Main Menu).</li>
<li> You may now pre-rotate pieces in the queue by right-clicking during a tile drop-in.</li>
<li> A Windows installer that&#8217;ll automatically install Java if needed. Works on 32-bit and 64-bit Windows (including Vista).</li>
<li> Added new rotation tutorial to Level 2.</li>
</ul>
<p>If you would like to play Wezzle test 7 (or any of the tests) and you are not currently on the email list, just send me an email and we can get that fixed right away.	</p>
]]></content:encoded>
			<wfw:commentRss>http://couchware.ca/www/kev/2009/06/17/wezzle-test-7-is-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning Scala</title>
		<link>http://couchware.ca/www/kev/2009/04/14/learning-scala/</link>
		<comments>http://couchware.ca/www/kev/2009/04/14/learning-scala/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 16:04:42 +0000</pubDate>
		<dc:creator>kev</dc:creator>
				<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[chapters]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[FP]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[lift]]></category>
		<category><![CDATA[object oriented programming]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[smalltalk]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/kev/?p=152</guid>
		<description><![CDATA[My copy of Programming in Scala finally arrived yesterday, and I have had a chance to read the first chapter. It looks to be a very interesting language. I have had a desire to learn functional programming for a long time, and I have a giant fascination with programming languages in general. Scala seems to [...]]]></description>
			<content:encoded><![CDATA[<p>My copy of <a href="http://www.amazon.com/Programming-Scala-Comprehensive-Step-step/dp/0981531601/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1239717940&amp;sr=8-1">Programming in Scala</a> finally arrived yesterday, and I have had a chance to read the first chapter. It looks to be a very interesting language. I have had a desire to learn functional programming for a long time, and I have a giant fascination with programming languages in general. Scala seems to be getting a lot of hype right now, and the ability to program both <a href="http://en.wikipedia.org/wiki/Imperative_programming">Imperatively </a>and <a href="http://en.wikipedia.org/wiki/Functional_programming">Functionally </a>is too hard to pass up.<br />
<span id="more-152"></span><br />
Getting the book turned out to be more annoying than I had anticipated. The book is fairly new and as such, not yet available on <a href="http://www.chapter.ca">Chapters.ca</a>. It is available at <a href="http://www.amazon.ca">Amazon.ca</a>, however, the copy listed has a 2-3 week waiting period before shipping. I am an impatient person and I decided to order it from <a href="http://www.amazon.com">Amazon.com</a> because it listed the book as In Stock.</p>
<p>I placed the order on April 1, paying extra for the medium-tier shipping package so that I could get the book within 3-5 days of shipping. Since the book was in stock I was hoping to have the book by the end of the week. The only reason I ordered from the U.S. site (which obviously cost more for conversion, shipping, customs etc.) was so i could get the book without waiting 2-3 weeks. This prior weekend was a long weekend and it would have been nice to have had the book to read while I had some time at home. However, by April 8, the book still had not shipped. This was inconceivable to me as it was STILL listed as In Stock on their website, why would it not have shipped? </p>
<p>I sent a strongly worded letter to Amazon customer service, and to their credit, they upgraded me to premium shipping and sent it out the next day. The said there was a problem with the order that he fixed and sent it out at the next available opportunity. I highly doubt there was actually a problem other than the fact that I complained. Long story short, I finally have the book. Even though Amazon customer service was pretty good about the matter, I should not have had to contact them in the first place and I did not get to read the book over the long weekend as I had hoped.</p>
<p>Anyway, back to Scala. Scala seems to be a pretty cool language. From what I gather so far (and I will update you as I know more about it) it combines Object Oriented Programming (OOP) principles with Functional Programming (FP). It allows for both Imperative (think Java, C++) and Functional (Erlang, Haskell) programming styles. It is not the only language to do this, many languages provide functional programming features within the language, such as closures, functions as first class objects etc. The most notable languages to do this would be Python and Ruby.</p>
<p>However, Scala is not a dynamic language. It is statically typed, with type inference, which looks like it could be very nice. Additionally, Scala&#8217;s OO model is not implemented in a half-assed fashion like Java (primitives, statics, &#8230;) but rather, everything is an object (in the vein of Smalltalk, Ruby, etc.). Finally, it is lightweight, choosing to bundle most features in external libraries (comes with a standard library) rather than in the language itself, (such as BigIntegers, Actors).</p>
<p>The really interesting thing about Scala, is that it uses a lot of the Java types but extends them using something called Traits. For example, it uses primitive Java ints, but in order to make them objects, it defines a trait that will map Scala commands to a custom implementation (kinda). An example of this is if you want to call a function on an int, Scala will first look to the Java implementation, if the function doesn&#8217;t exist (which it wont because an int is a primitive) it will look to see if there are any traits defined, (which there are because its part of the Scala language) and then look for the function there. Scala uses these traits as means of wrapping the Java libraries in a nice way for use with the Scala language. It makes external libraries seem as if they are part of the Scala language, which is pretty nice. The beauty of this is, you can define your own traits and extend classes however you see fit. As well, you can use traits as lightweight interfaces, defining partial methods and enforcing multiple traits in a pseudo multiple inheritance scheme. Pretty powerful (if you understand what I just said anyway). I&#8217;m not 100% clear on traits so don&#8217;t get mad if some of the info I just mentioned is wrong.</p>
<p>Scala is also a fully functional language, borrowing some great ideas from other functional languages such as Haskell and Erlang. Of note, Scala uses an implementation of Erlang&#8217;s Actor&#8217;s shared memory model to accomplish parallel programming. Erlang&#8217;s model has been hugely successful and I am interested to see exactly how I can utilize this feature. </p>
<p>Scala&#8217;s name comes from &#8220;Scalable Language.&#8221; I&#8217;m not sure exactly what makes Scala so scalable, some of the things I&#8217;ve seen from my brief introduction is its use of traits, its integration with the Java standard library, its ability to run on the JVM and its Erlang-eque concurrency model. </p>
<p>There was a great question <a href="http://couchware.ca/blogs/cam">Cam</a> pointed out on <a href="http://stackoverflow.com/questions/648964/why-is-the-lift-web-framework-scalable">Stack Overflow</a> which talks a bit about what makes the <a href="http://liftweb.net/">Lift</a> web framework (written in Scala) so scalable. It is really interesting, and their take on threading is a good one in my opinion. Something I hope to maybe take advantage of with my own stuff.</p>
<p>I have to say that I am pretty excited to learn Scala. It seems like it could be a great language that is still undergoing heavy development and is very extendable. Ultimately I would like to combine Scala with some of my Java programming, something that I see as Scala&#8217;s (and all JVM languages) best feature. I believe this is still something that is not entirely EASY to accomplish. Something that I would like to see, and I am sure is on the list of things to do, is the ability to mix JVM languages transparently, without the need to call the specific compilers for the specific classes. Maybe I will work on that as a side project.</p>
<p>Scala is being touted by many as the next &#8220;Big&#8221; language. I don&#8217;t know if that&#8217;s necessarily the case, but it sure does seem like a nice language. Maybe it will quench my thirst for new languages temporarily? Who knows. I also purchased <a href="http://www.amazon.com/Programming-Language-Pragmatics-Third-Michael/dp/0123745144/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1239724031&amp;sr=1-1">Programming Language Pragmatics</a> with a mild desire to create my own language at some point. Perhaps I will be able to leverage some ideas from Scala when doing so.</p>
<p>This will be my first serious venture into the FP world (I have a little experience with Scheme, however, that was a long time ago, in a galaxy far far away&#8230;). I am already familiar with a bunch of functional techniques, such as closures/lambdas, but I have never really programmed in a functional way for something serious. Hopefully Scala turns out to be as nice as it appears to be, as I am excited to try the Lift framework and to start mixing functional programming with my current code.</p>
]]></content:encoded>
			<wfw:commentRss>http://couchware.ca/www/kev/2009/04/14/learning-scala/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Willing to sell out</title>
		<link>http://couchware.ca/www/kev/2009/04/07/willing-to-sell-out/</link>
		<comments>http://couchware.ca/www/kev/2009/04/07/willing-to-sell-out/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 17:16:21 +0000</pubDate>
		<dc:creator>kev</dc:creator>
				<category><![CDATA[Wezzle]]></category>
		<category><![CDATA[adium]]></category>
		<category><![CDATA[digsby]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[instant messaging]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/kev/?p=149</guid>
		<description><![CDATA[Cam and I were talking about our mutual love for the IM tool Digsby which we both use to track e-mails, social networks and Instant messaging. If you like the popular Mac tool Adium, you will love Digsby. Even if you have never heard of Adium, Digsby is worth checking out.

Anyway, we were talking about [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://couchware.ca/blogs/cam">Cam </a>and I were talking about our mutual love for the IM tool <a href="http://www.digsby.com/">Digsby</a> which we both use to track e-mails, social networks and Instant messaging. If you like the popular Mac tool <a href="http://www.adiumx.com/">Adium</a>, you will love Digsby. Even if you have never heard of Adium, Digsby is worth checking out.</p>
<p><span id="more-149"></span></p>
<p>Anyway, we were talking about Digsby, and I mentioned that one of the things I dislike is that if you use Digsby for <a href="http://www.twitter.com">Twitter</a>, they automatically make you follow the Digsby Twitter feed. This is something that is very irritating, I don&#8217;t want to have to follow them or figure out how to un-follow them. This should be an option or something. </p>
<p>Additionally, Cam mentioned (and i agree) that he doesn&#8217;t like how they try to get you to install around 10 different applications when you install Digsby. This is something that I find in a lot of programs. I often get asked if I want to install <a href="http://www.yahoo.com">Yahoo!</a> toolbar or some such program and this irritates me to no end. I wish they would stop doing that stuff.</p>
<p>However, Cam asked me the following: If Yahoo! approached us and said if you package Yahoo! toolbar with your application, we will pay you $100,000, what would you say? The answer, obviously, was a resounding yes. So there you have it. We are willing to sell out, and I don&#8217;t even know what the price point for our selling out would be. So Yahoo! or <a href="http://www.google.ca">Google </a>or anyone else out there. If you want to pay us money to package your application, we are willing to do so.</p>
]]></content:encoded>
			<wfw:commentRss>http://couchware.ca/www/kev/2009/04/07/willing-to-sell-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;ve joined the dark side</title>
		<link>http://couchware.ca/www/kev/2009/03/21/ive-joined-the-dark-side/</link>
		<comments>http://couchware.ca/www/kev/2009/03/21/ive-joined-the-dark-side/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 03:48:49 +0000</pubDate>
		<dc:creator>kev</dc:creator>
				<category><![CDATA[twitter]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[micro blogging]]></category>
		<category><![CDATA[myspace]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[social networking]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/kev/?p=129</guid>
		<description><![CDATA[I have joined Twitter. I generally hate flavour of the month technology fads and Twitter is no exception. I am already really annoyed with the media coverage of Twitter. It seems like every time I turn on the radio I hear about it. That being said, you can follow me here.

I mainly joined Twitter so [...]]]></description>
			<content:encoded><![CDATA[<p>I have joined <a href="http://www.twitter.com">Twitter</a>. I generally hate flavour of the month technology fads and Twitter is no exception. I am already really annoyed with the media coverage of Twitter. It seems like every time I turn on the radio I hear about it. That being said, you can follow me <a href="http://twitter.com/kgrad">here</a>.</p>
<p><span id="more-129"></span></p>
<p>I mainly joined Twitter so I could follow the likes of <a href="http://ejohn.org/blog/">John Resig</a> and <a href="http://gafter.blogspot.com/">Neal Gafter</a> as well as some other interesting techie people and I am already mildly annoyed with the service. </p>
<p>I expected that Twitter would offer me a client similar to Live Messenger or Google Talk. Instead, I had to find a third-party client. Furthermore the one everyone uses is only available on Mac and has ads unless you pay $15. If anyone knows of a good windows standalone client, please let me know. </p>
<p>Additionally, I have been trying Twitter for all of 2 hours now, and I&#8217;ve realized this whole micro-blogging thing really irks me. I am following people I consider to be really smart not because I care what they ate for dinner, or what videos they are currently watching. I am following them because I want to know more about what they are working on and thinking in terms of technology.</p>
<p>That being said, if and when I start following my actual real life friends, I will be interested in what they are doing currently. Maybe Twitter should take that into account? Have different classifications of tweets, ones for personal friends and ones for the public? Or maybe Twitter just isn&#8217;t for me. Perhaps I should just stick with traditional blogs and instant messenging clients. </p>
<p>Also, there are huge privacy concerns with an app like this. Although there is an option to have only certain people see your updates, the whole spirit of Twitter is to be a public micro-blogging system. I don&#8217;t even want to get into how careful you have to be with what you post there. Sometimes public messenging can get you in trouble. Something many people have found out the hard way with facebook. Also something <a href="http://sports.espn.go.com/nba/news/story?id=3990853">Charlie Villanueva</a> recently found out.</p>
<p>From a technology standpoint, Twitter is an alright service I guess, although for me it really lacks the <b>wow</b> factor. It seems to me that its a pretty direct translation of IP<a href="http://en.wikipedia.org/wiki/Multicast">multicast</a> leveraging <a href="http://en.wikipedia.org/wiki/SMS">SMS</a> and pretty much nothing else. </p>
<p>Twitter seems like a pretty linear service, unless I&#8217;m missing something. I&#8217;m guessing that it&#8217;s success is due to the fact that they really targetted mobile phones, but in reality it just seems to be a gimped version of RSS. I don&#8217;t even think they were the first to offer micro-blogging. Additionally, there are alternative open source models which have pretty much the same functionality for micro-blogging, like <a href="http://www.google.ca">Google</a> <a href="http://en.wikipedia.org/wiki/Jaiku">Jaiku</a> and facebook&#8217;s new (and annoying) what&#8217;s on your mind? feature.</p>
<p>What does Twitter really offer me? It&#8217;s not a full feature web app like facebook or <a href="http://www.myspace.com">myspace</a>, its not an internet overlord like Google&#8230; Their one advantage is SMS. They don&#8217;t even have downloadable clients from what I can tell. They rely on user made clients. </p>
<p>It&#8217;s cool that they already have a bunch of people using it (I almost added Shaq to my watch list). But will it really have the staying power once the initial novelty of the app wares off? Their functionality isn&#8217;t that hard to reproduce and improve upon&#8230;</p>
<p>Unless Twitter leverages the SMS platform in some other unique way or they expand or add some other functionality, I will be surprised if it is anything other than a flavour of the month micro-blogging tool (for me anyway).  Which is fine by me, there are enough programs I check every day anyway. But I suspect with its rush of popularity, we will hopefully be seeing something more interesting coming from the Twitter people sometime soon. Until that time comes, let me know of some interesting people you think I should be following. </p>
]]></content:encoded>
			<wfw:commentRss>http://couchware.ca/www/kev/2009/03/21/ive-joined-the-dark-side/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wezzle Collision Generator</title>
		<link>http://couchware.ca/www/kev/2009/03/13/wezzle-collision-generator/</link>
		<comments>http://couchware.ca/www/kev/2009/03/13/wezzle-collision-generator/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 04:10:25 +0000</pubDate>
		<dc:creator>kev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Wezzle]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/kev/?p=124</guid>
		<description><![CDATA[I have a fascination with programming languages. I have been reading up on many different ones trying to get a feel for them all. I enjoy learning about the different syntaxes and what the advantages are of the different paradigms. I find most of the languages offer really interesting concepts and benefits.

Last night I was [...]]]></description>
			<content:encoded><![CDATA[<p>I have a fascination with programming languages. I have been reading up on many different ones trying to get a feel for them all. I enjoy learning about the different syntaxes and what the advantages are of the different paradigms. I find most of the languages offer really interesting concepts and benefits.<br />
<span id="more-124"></span></p>
<p>Last night I was hacking around with <a href="http://www.ruby-lang.org/en/">Ruby</a> and decided that to teach myself how to program better I would do something interesting for Wezzle. I had the idea of taking the <a href="http://couchware.ca/blogs/kev/2009/01/27/wezzle-xml/">XML markup for our achievements</a> and making some sort of generator using our achievement pseudo-language.</p>
<p>Our achievement language basically amounts to what is known in computing as a <a href="http://en.wikipedia.org/wiki/Domain-specific_language">Domain Specific Language (DSL).</a> Luckily for me Ruby is a pretty good language for writing DSL&#8217;s. </p>
<p>I decided to start with the achievements that I find to be the hardest to write, COLLISION. A COLLISION occurs between 1 or many items. There are two seperate types of collisions which can be defined as either an AND or an INTO relationship. These can be seen in the following two examples:</p>
<p>Example 1:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:Consolas, monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;achievement</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;A Tale of Two Rockets&quot;</span> <span style="color: #000066;">difficulty</span>=<span style="color: #ff0000;">&quot;SILVER&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Fire a rocket into another rocket.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rule</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;COLLISION&quot;</span> <span style="color: #000066;">operation</span>=<span style="color: #ff0000;">&quot;BETWEEN&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;ROCKET&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;ROCKET&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/achievement<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Example 2:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:Consolas, monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;achievement</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;A Tale of Two Rockets&quot;</span> <span style="color: #000066;">difficulty</span>=<span style="color: #ff0000;">&quot;SILVER&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Fire a rocket into another rocket.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rule</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;COLLISION&quot;</span> <span style="color: #000066;">operation</span>=<span style="color: #ff0000;">&quot;BETWEEN&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;ROCKET&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;ROCKET&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/achievement<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>While these two examples may look the same, they mean two different things. The first one can be written as COLLISION BETWEEN ROCKET AND ROCKET simply means that two rockets will be activated in a single turn. The second one however would be written like COLLISION BETWEEN ROCKET INTO ROCKET and means a rocket will be fired and activate another rocket by hitting it.</p>
<p>I have written a generator in ruby that takes an achievement (currently only collisions) in the following form:</p>
<p>BEGIN COLLISION<br />
achievement:Rocketeer:BRONZE<br />
description:Fire a rocket into a rocket and fire a rocket and a rocket.<br />
rule:COLLISION BETWEEN ROCKET INTO ROCKET<br />
rule:COLLISION BETWEEN ROCKET AND ROCKET<br />
END</p>
<p>This is currently defined within the program and will output the properly formatted and tabbed XML which you can then paste into your achievements.xml file. The goal is to have it work for all achievements, and I will keep you updated as to the progress should I choose to continue. As it stands, you can find the current version <a href="http://couchware.ca/blogs/WezzleCollisionGen.rb">here </a>although it&#8217;s a little bit ugly. Please note, you must have ruby 1.9+ in order to run it.</p>
]]></content:encoded>
			<wfw:commentRss>http://couchware.ca/www/kev/2009/03/13/wezzle-collision-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

