<?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>Th30z - Coding on the Fly &#187; Networking</title>
	<atom:link href="http://th30z.netsons.org/category/unix-c/networking/feed/" rel="self" type="application/rss+xml" />
	<link>http://th30z.netsons.org</link>
	<description>Matteo Bertozzi, Objective-C, Cocoa, C, C++, Qt4, iPhone, Mac OS X, Open Moko, Matteo Bertozzi Development</description>
	<lastBuildDate>Sun, 22 Nov 2009 09:47:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>[TIP] Generic Binary Format</title>
		<link>http://th30z.netsons.org/2009/08/tip-generic-binary-format/</link>
		<comments>http://th30z.netsons.org/2009/08/tip-generic-binary-format/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 11:26:31 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Binary Format]]></category>
		<category><![CDATA[Protocols]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1156</guid>
		<description><![CDATA[I Love use Binary formats, instead of XML, and JSON. Here is my Generic Binary Format for data transmissions or serializations. Data is composed by three blocks. The first one 1byte that describe all information about the object, like &#8220;is a single Int object&#8221; or &#8220;is a list&#8221;, then tells you the second block length. [...]]]></description>
			<content:encoded><![CDATA[<p>I Love use Binary formats, instead of XML, and JSON. Here is my Generic Binary Format for data transmissions or serializations. Data is composed by three blocks. The first one 1byte that describe all information about the object, like &#8220;is a single Int object&#8221; or &#8220;is a list&#8221;, then tells you the second block length. The second block contains the size of the third block (The Data-Block) or the Number of Items in List.</p>
<p><a href="http://th30z.netsons.org/wp-content/uploads/Generic-Binary-Format.png"><img class="aligncenter size-full wp-image-1155" title="Generic Binary Format" src="http://th30z.netsons.org/wp-content/uploads/Generic-Binary-Format.png" alt="Generic Binary Format" width="577" height="289" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/08/tip-generic-binary-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unified Notification Service: Avoid The Wheel Reinvention</title>
		<link>http://th30z.netsons.org/2009/08/unified-notification-service-avoid-the-wheel-reinvention/</link>
		<comments>http://th30z.netsons.org/2009/08/unified-notification-service-avoid-the-wheel-reinvention/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 04:43:31 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Notification Service]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1118</guid>
		<description><![CDATA[Every programmer loves to reinvent the wheel, and reinventing the wheel is still my primary hobby. Sometimes you need to reimplement a Network protocol to use with your favorite language/library, sometimes is only for fun, but if you&#8217;re in the Business World maybe is &#8220;better&#8221; (faster) to use one of the thousand existing libraries.
In the [...]]]></description>
			<content:encoded><![CDATA[<p>Every programmer loves to reinvent the wheel, and reinventing the wheel is still my primary hobby. Sometimes you need to reimplement a Network protocol to use with your favorite language/library, sometimes is only for fun, but if you&#8217;re in the Business World maybe is &#8220;better&#8221; (faster) to use one of the thousand existing libraries.</p>
<p>In the most cases you need to reimplement a Protocol to embed it in your application, and sometimes you have to reimplement two/three protocols that does the same job like IM Protocols (XMPP, AIM, Yahoo&#8230;).</p>
<p>A better solution, that avoid you to reinvent the wheel is to use an existent library to handle the protocol(s) that you need, and build an Abstract Interface, with your data format, that allows you to use a generic way to communicate between various provider. Below you can find a graphical example of what I mean.</p>
<p><a href="http://th30z.netsons.org/wp-content/uploads/UnifiedNotificationService.png"><img class="aligncenter size-full wp-image-1119" title="Unified Notification Service" src="http://th30z.netsons.org/wp-content/uploads/UnifiedNotificationService.png" alt="Unified Notification Service" width="513" height="371" /></a></p>
<p>You can have many providers, written in different languages. These providers talk with the Notification Service providing an abstract interface for the Apps. In this way, the end App has just to say &#8220;Write a Mail To X&#8221;, &#8220;Download Todays Mail&#8221;, &#8220;Send an IM to X&#8221;&#8230; and you can intercept notification to displays as a popup on your desktop&#8230; or something similar.</p>
<p><em>This solution will be used in <a title="MokoTouch Project" href="http://th30z.netsons.org/mokotouch">MokoTouch Project</a>, to provide Core Services to the Apps. For more information send me a mail.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/08/unified-notification-service-avoid-the-wheel-reinvention/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Bit of Distributed Computation&#8230;</title>
		<link>http://th30z.netsons.org/2009/08/a-bit-of-distributed-computation/</link>
		<comments>http://th30z.netsons.org/2009/08/a-bit-of-distributed-computation/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 17:23:26 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Distributed Computation]]></category>
		<category><![CDATA[Parallel Computation]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1101</guid>
		<description><![CDATA[In the last months I&#8217;ve worked on various 2D rendering projects, that requires lots of row power to be executed in smallest time as possible.
The rendering result is an aggregation of components (or better, Group of Components) that can be rendered independently of each other in a  process because each components has its own input [...]]]></description>
			<content:encoded><![CDATA[<p>In the last months I&#8217;ve worked on various 2D rendering projects, that requires lots of row power to be executed in smallest time as possible.</p>
<p>The rendering <em>result is an aggregation of components</em> (or better, Group of Components) that <strong>can be rendered independently</strong> of each other in a  process because each components has its own input data and until the aggregation process starts there&#8217;re <strong>no dependencies</strong> between components. In a few words, foreach input data I&#8217;ve to call a Render method that returns the &#8220;computed&#8221; data, that at the end will be aggregated with all the computed values.</p>
<p>So, how speed-up the rendering? The standard answer is using <strong>Threads</strong>, <em>to take advantage of multi-core system</em>. But I need lots row power and lots of core to be fast enought. Another solution that doesn&#8217;t require to spent a lot of money for a faster computer it to <strong>distribute the computation across different machines</strong>. And this is my attempt&#8230;</p>
<p><a href="http://th30z.netsons.org/wp-content/uploads/DistributedComputation-Schema-01.png"><img class="aligncenter size-full wp-image-1102" title="Distributed Computation Arch" src="http://th30z.netsons.org/wp-content/uploads/DistributedComputation-Schema-01.png" alt="Distributed Computation Arch" width="533" height="445" /></a></p>
<p>The <strong>Master</strong> receive an array of elements as input and splits up it according to the number of the available Nodes (Machines), and foreach node assigns its sub-array and sends an &#8220;informative message&#8221; to the node.</p>
<p>The <strong>Node</strong> waits for an &#8220;informative message&#8221; and when it has received it, starts its computation. Foreach Data Item that fetch runs the Computation and sends back the result.</p>
<p>The Master decompose data into <em>equal-size partitions</em>, so each node has  an equal-size queue to process, but if someone finishes its job and there&#8217;re more data to process (in someone else queue) The Master dequeue couple of items from the slower node queue and add to the queue of the one that has finished its job. In this way you&#8217;ve done your computation faster then ever, and <strong>if one machine crashes</strong> (slow one case) its job will be taken by someone else that has finished its own.</p>
<p><em>And this is just a bit of General Theory, but the implementation is really simple. Maybe I&#8217;ll try to reimplement something more generic in the near future (October, November) when I&#8217;ll have a bit more of free time.</em> If you&#8217;ve any question send me a mail!</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/08/a-bit-of-distributed-computation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reliable Protocol on Unreliable Channel</title>
		<link>http://th30z.netsons.org/2009/06/reliable-protocol-on-unreliable-channel/</link>
		<comments>http://th30z.netsons.org/2009/06/reliable-protocol-on-unreliable-channel/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 05:52:56 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Protocols]]></category>
		<category><![CDATA[Theory]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=963</guid>
		<description><![CDATA[When you work with Unreliable communication channel (like UDP), you need to implement your own &#8220;Reliable Mechanism&#8221; to be sure that packet that you&#8217;ve send was received correctly. Here there&#8217;s my attempt.
Reliable Transmitter:
The schema below shows the operations that reliable transmitter has to do. &#8220;Red&#8221; are &#8220;error or unexpected operations&#8221;, Green are &#8220;expected operations&#8221;, Blue [...]]]></description>
			<content:encoded><![CDATA[<p>When you work with Unreliable communication channel (like <a title="UDP User Datagram Protocol" href="http://en.wikipedia.org/wiki/User_Datagram_Protocol">UDP</a>), you need to implement your own &#8220;Reliable Mechanism&#8221; to be sure that packet that you&#8217;ve send was received correctly. Here there&#8217;s my attempt.</p>
<p><strong>Reliable Transmitter</strong>:</p>
<p>The schema below shows the operations that reliable transmitter has to do. &#8220;Red&#8221; are &#8220;error or unexpected operations&#8221;, Green are &#8220;expected operations&#8221;, Blue are TX Operations.</p>
<p style="text-align: left;"><a href="http://th30z.netsons.org/wp-content/uploads/ReliablePacketTx.png"><img class="aligncenter size-full wp-image-962" title="Reliable Packet Tx" src="http://th30z.netsons.org/wp-content/uploads/ReliablePacketTx.png" alt="Reliable Packet Tx" width="589" height="119" /></a>Transmitter send a packet and waits for the ACK packet (sended by receiver). If ACK doesn&#8217;t arrive before the Tx Timeout packet is resended. When ACK arrive Tx send the CACK (Confirm ACK) packet and waits for a timeout, if another ACK Arrive TX resend the CACK, this because receiver doesn&#8217;t have the confirm of transmitter. When TX timeout all is done, and the packet is sended correctly.</p>
<p><strong>Reliable Receiver</strong>:</p>
<p>The schema below shows the operations that reliable receiver has to do. &#8220;Red&#8221; are &#8220;error or unexpected operations&#8221;, Green are &#8220;expected operations&#8221;, Blue are Rx Operations.</p>
<p style="text-align: left;"><a href="http://th30z.netsons.org/wp-content/uploads/ReliablePacketRx.png"><img class="aligncenter size-full wp-image-967" title="Reliable Packet Rx" src="http://th30z.netsons.org/wp-content/uploads/ReliablePacketRx.png" alt="Reliable Packet Rx" width="456" height="132" /></a>When RX receive a Packet sends an ACK, and waits for the CACK, if CACK doesn&#8217;t arrive before timeout RX resend the ACK. When CACK arrive all is done. We&#8217;ve received the packet and the transmitter knows that we&#8217;ve received it.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/06/reliable-protocol-on-unreliable-channel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenSSL: SSL Client/Server Example</title>
		<link>http://th30z.netsons.org/2009/06/openssl-ssl-clientserver-example/</link>
		<comments>http://th30z.netsons.org/2009/06/openssl-ssl-clientserver-example/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 04:53:51 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[OpenSSL]]></category>
		<category><![CDATA[Unix C]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=936</guid>
		<description><![CDATA[I&#8217;m experimenting a bit with the new iPhone 3.0 SDK, Core Data, Game Kit, Push Notification Service and so on&#8230; 
I&#8217;m using C, so today a little Example of SSL Client/Server written in C using OpenSSL, I&#8217;ve written a small wrapper for SSL Socket, and here is How to use it.


/* SERVER CODE
 * ==============================
 [...]]]></description>
			<content:encoded><![CDATA[<p><em>I&#8217;m experimenting a bit with the new iPhone 3.0 SDK, Core Data, Game Kit, Push Notification Service and so on&#8230; </em></p>
<p>I&#8217;m using C, so today a little Example of SSL Client/Server written in C using OpenSSL, I&#8217;ve written a small wrapper for SSL Socket, and here is How to use it.<br />
<code></p>
<pre>
/* SERVER CODE
 * ==============================
 */
SFSocketGlobalInit();       /* Initialize SSL */

/* Alloc Socket, Initialize SSL and Listen */
SFSocket *socket = SFSocketAlloc();
SFSocketInit(socket, CA_FILE, DH_FILE, KEY_FILE, KEY_PASSWORD, NULL);
SFSocketListen(socket, INADDR_ANY, PORT);

do {
   SFSocket *clientSocket;
   char buffer[64];
   int rdSize;

   /* Accept Client Connection */
   if ((clientSocket = SFSocketAccept(socket)) == NULL)
       break;        

   /* Read Data from Client */
   if ((rdSize = SFSocketRead(clientSocket, buffer, 64 - 1)) &gt; 0) {
       buffer[rdSize] = '\0';
       printf(&quot;Client: %s\n&quot;, buffer);
   }

   /* Write to Client */
   strcpy(buffer, &quot;Hello Client!&quot;);
   SFSocketWrite(clientSocket, buffer, strlen(buffer));

   /* Disconnect Client */
   SFSocketRelease(clientSocket);
} while (1);

/* Close and Release Socket Resources */
SFSocketRelease(socket);
</pre>
<p></code><br />
Above you&#8217;ve the simplified server code (without error check!) and below you&#8217;ve the client code. The client try to connects to server, send an &#8220;Hello&#8221; message and the server reply with other greetings.<br />
<code></p>
<pre>
/* CLIENT CODE
 * ==============================
 */
SFSocketGlobalInit();       /* Initialize SSL */

/* Alloc Socket, Initialize SSL */
SFSocket *socket = SFSocketAlloc();
SFSocketInit(socket, CA_FILE, NULL, KEY_FILE, KEY_PASSWORD, NULL);

/* Connect to Host */
SFSocketConnectToHost(socket, HOSTNAME, PORT);

/* Send Message to Server */
char buffer[64];
strcpy(buffer, &quot;Hello from Client!&quot;);
SFSocketWrite(socket, buffer, strlen(buffer));

/* Read Message from Server */
if ((rdSize = SFSocketRead(socket, buffer, 64 - 1)) &gt; 0) {
   buffer[rdSize] = '\0';
   printf(&quot;Server: %s\n&quot;, buffer);
}

/* Close and Release Socket Resources */
SFSocketRelease(socket);
</pre>
<p></code></p>
<p>Remember that you need to generate, at least, the Authority Certificate, Server Certificate and Clients Certificates. and here is How to do it.<br />
<code></p>
<pre>
- AUTHORITY Certificate:
 openssl genrsa -des3 -out ca.key 1024
 openssl req -new -x509 -key ca.key -out ca.crt

- SERVER Certificate
 openssl genrsa -des3 -out server.key 1024
 openssl req -new -key server.key -out server.csr
 openssl x509 -req -in server.csr -out server.crt -sha1 \
                   -CA ca.crt -CAkey ca.key -CAcreateserial 

- CLIENT Certificate
 openssl genrsa -des3 -out client.key 1024
 openssl req -new -key client.key -out client.csr
 openssl x509 -req -in client.csr -out client.crt -sha1 \
                   -CA ca.crt -CAkey ca.key -CAcreateserial
</pre>
<p></code></p>
<p>The Full Source Code is Available Here: <a title="SSL Client/Server Example" href="http://th30z.netsons.org/wp-content/uploads/SSL-Example.tar.bz2">SSL Client/Server Example Source Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/06/openssl-ssl-clientserver-example/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
