<?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>Gaurav &#187; C#</title>
	<atom:link href="http://allyourcodearebelongto.me/blog/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://allyourcodearebelongto.me/blog</link>
	<description>All About Everything</description>
	<lastBuildDate>Sun, 23 Nov 2008 19:44:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating a chat application using Socket in Silverlight</title>
		<link>http://allyourcodearebelongto.me/blog/2008/04/17/creating-a-chat-application-using-socket-in-silverlight/</link>
		<comments>http://allyourcodearebelongto.me/blog/2008/04/17/creating-a-chat-application-using-socket-in-silverlight/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 21:12:52 +0000</pubDate>
		<dc:creator>Gaurav</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[chat application]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[socket]]></category>
		<category><![CDATA[visual studio 2008]]></category>

		<guid isPermaLink="false">http://techblogging.wordpress.com/2008/04/17/creating-a-chat-application-using-socket-in-silverlight/</guid>
		<description><![CDATA[Here I will explain how to communicate with the server using the Socket class. The socket class allows Asynchronous communication between the client and server. This application will show how to share data in real-time in two different browser windows using Silverlight.
This application will contain two parts:

Server application using Ruby.
Client application using C# in Silverlight.

Creating [...]]]></description>
			<content:encoded><![CDATA[<p>Here I will explain how to communicate with the server using the <strong>Socket </strong>class. The socket class allows Asynchronous communication between the client and server. This application will show how to share data in real-time in two different browser windows using Silverlight.</p>
<p>This application will contain two parts:</p>
<ol>
<li>Server application using Ruby.</li>
<li>Client application using C# in Silverlight.</li>
</ol>
<h5><u>Creating the server application:</u></h5>
<p>Making a multi-threaded server application in ruby is really easy and that is the reason I chose Ruby to create the server in least amount of time possible.</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> require <span style="color:#008000;">'socket'</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span> HOST = <span style="color:#008000;">'localhost'</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span> PORT = 4505</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span> server = TCPServer.<span style="color:#0000ff;">new</span>(HOST, PORT)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span> # array <span style="color:#0000ff;">to</span> store all the active connections</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span> sessions = []</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span> <span style="color:#0000ff;">while</span> (session = server.accept)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>   # push the current session(socket) <span style="color:#0000ff;">in</span> the array</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>   sessions &lt;&lt; session</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>   # initialize a <span style="color:#0000ff;">new</span> thead <span style="color:#0000ff;">for</span> <span style="color:#0000ff;">each</span> connection</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>   Thread.<span style="color:#0000ff;">new</span>(session) <span style="color:#0000ff;">do</span> |local_session|</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>     # <span style="color:#0000ff;">each</span> time a client sends some data send it <span style="color:#0000ff;">to</span> all the connections</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>     <span style="color:#0000ff;">while</span>(<span style="color:#0000ff;">true</span>)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span>       data = local_session.gets</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  18:</span>       sessions.<span style="color:#0000ff;">each</span> <span style="color:#0000ff;">do</span> |s| </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  19:</span>         begin</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  20:</span>           s.puts data</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  21:</span>         rescue Errno::ECONNRESET</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  22:</span>           # an exception <span style="color:#0000ff;">is</span> raised, that means the connection <span style="color:#0000ff;">to</span> the client <span style="color:#0000ff;">is</span> broken</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier,
 monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  23:</span>           sessions.delete(s)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  24:</span>         <span style="color:#0000ff;">end</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  25:</span>       <span style="color:#0000ff;">end</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  26:</span>     <span style="color:#0000ff;">end</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  27:</span>   <span style="color:#0000ff;">end</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  28:</span> end</pre>
</div>
</div>
<p>&nbsp;</p>
<p><a href="http://pastie.caboo.se/182562">Here is the pastie</a>.</p>
<p>Save this file as chat_server.rb</p>
<p><span id="more-88"></span></p>
<p>&nbsp;</p>
<p>This code is really quite simple and all it is doing is creating a new thread for each client connection and rejecting the invalid ones. Whenever a client sends some data it is propagated to all the clients.</p>
<p>&nbsp;</p>
<h5><u>Creating the client application:</u></h5>
<p>This is the difficult part among the two. As I mentioned earlier I will be using the <strong>Socket </strong>class. The important instance methods of this class are:</p>
<ol>
<li>ConnectAsync</li>
<li>SendAyns</li>
<li>ReceiveAync</li>
</ol>
<p>As their names suggest all of them are asynchronous. I am not sure of the reason. May be its because the communication does not block the UI thread and making it a bad experience for the client or may be its because of browser&#8217;s limitations.</p>
<p>Also in the beta-1 implementation the Silverlight <strong>Socket</strong> class only allows connection to 4502 &#8211; 4532 port range. I guess this limitation will be removed in the later versions.</p>
<p>Open up Visual Studio 2008 (with Silverlight <a href="http://techblogging.wordpress.com/2008/03/05/silverlight-20-beta-1-now-available-and-10-version-ported-to-nokia-mobiles/">tools</a> installed. You can also download a trial version of Visual Studio 2008 from <a href="http://msdn2.microsoft.com/en-us/vstudio/products/aa700831.aspx">here</a>). And create a new project:</p>
<p><a href="http://allyourcodearebelongto.me/blog/wp-content/uploads/2008/04/image1.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="447" alt="image" src="http://allyourcodearebelongto.me/blog/wp-content/uploads/2008/04/image-thumb1.png" width="588" border="0"></a> </p>
<p>Name the application ChatClient and select rest of the default options.</p>
<p>Run the application. Visual Studio will prompt you to enable debugging, click OK to enable debugging and continue.</p>
<p>Add the <strong>System.net </strong>assembly to add the Socket class to solution.</p>
<p><u>Now to make a connection to the server we can use the Socket class:</u></p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> socket = <span style="color:#0000ff;">new</span> Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> SocketAsyncEventArgs connectEventArgs = <span style="color:#0000ff;">new</span> SocketAsyncEventArgs();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span> connectEventArgs.RemoteEndPoint = IP_END_POINT;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span> connectEventArgs.Completed += <span style="color:#0000ff;">new</span> EventHandler&lt;SocketAsyncEventArgs&gt;(connectEventArgs_Completed);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span> socket.ConnectAsync(connectEventArgs);</pre>
</div>
</div>
<p>Here <strong>IP_END_POINT </strong>is an object of DnsEndPoint class and basically points to the server. I will be showing the code for it later for simplicity.</p>
<p>In the above code I created an instances of <strong>Socket </strong>class and <strong>SocketAsyncEventArgs </strong>class. The latter does the event handling for the former. So when the connection is complete it will just ca a event handler and then we can start sending/receiving data to server.</p>
<p><u>Code for sending data to the server:</u></p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> sendEventArgs = <span style="color:#0000ff;">new</span> SocketAsyncEventArgs();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> sendEventArgs.RemoteEndPoint = IP_END_POINT;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span> List&lt;ArraySegment&lt;<span style="color:#0000ff;">byte</span>&gt;&gt; l = <span style="color:#0000ff;">new</span> List&lt;ArraySegment&lt;<span style="color:#0000ff;">byte</span>&gt;&gt;();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span> l.Add(<span style="color:#0000ff;">new</span> ArraySegment&lt;<span style="color:#0000ff;">byte</span>&gt;(Encoding.UTF8.GetBytes(sendBox.Text + <span style="color:#006080;">"\n"</span>)));</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span> sendEventArgs.BufferList = l;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span> socket.SendAsync(sendEventArgs);</pre>
</div>
</div>
<p>&nbsp;</p>
<p><strong>Socket </strong>uses a <strong>List</strong> to fill the data buffer. I have appended a <strong>&#8220;\n&#8221;</strong> in the data so that it is handled properly at the server.</p>
<p><u>Code to receive data from the server:</u></p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">void</span> connectEventArgs_Completed(<span style="color:#0000ff;">object</span> sender, SocketAsyncEventArgs e)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     e.Completed -= <span style="color:#0000ff;">new</span> EventHandler&lt;SocketAsyncEventArgs&gt;(connectEventArgs_Completed);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     e.Completed += <span style="color:#0000ff;">new</span> EventHandler&lt;SocketAsyncEventArgs&gt;(receiveEventArgs_Completed);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>     transferBuffer = <span style="color:#0000ff;">new</span> <span style="color:#0000ff;">byte</span>[BUFFER_SIZE];</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>     e.SetBuffer(transferBuffer, 0, transferBuffer.Length);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>     socket.ReceiveAsync(e);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span> }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span> <span style="color:#0000ff;">void</span> receiveEventArgs_Completed(<span style="color:#0000ff;">object</span> sender, SocketAsyncEventArgs e)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>     String a = Encoding.UTF8.GetString(transferBuffer, e.Offset, e.BytesTransferred);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>     SetText(a);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>     socket.ReceiveAsync(e);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span> }</pre>
</div>
</div>
<p>&nbsp;</p>
<p>When the connection to the server is complete the client begins to wait for the server to send data. This is done by removing the old event handler an creating a new one to receive the data. Also we need to initialise buffer so that incoming data can be received in it.</p>
<p>That is the basic structure you need to make for Asynchronous data transfer using <strong>Socket</strong> class.</p>
<h5><u>The full code:</u></h5>
<p><u>Page.xaml.cs</u></p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">using</span> System;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> <span style="color:#0000ff;">using</span> System.Collections.Generic;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span> <span style="color:#0000ff;">using</span> System.Linq;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span> <span style="color:#0000ff;">using</span> System.Windows;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span> <span style="color:#0000ff;">using</span> System.Windows.Controls;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span> <span style="color:#0000ff;">using</span> System.Windows.Documents;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span> <span style="color:#0000ff;">using</span> System.Windows.Input;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span> <span style="color:#0000ff;">using</span> System.Windows.Media;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span> <span style="color:#0000ff;">using</span> System.Windows.Media.Animation;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span> <span style="color:#0000ff;">using</span> System.Windows.Shapes;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span> <span style="color:#0000ff;">using</span> System.Net.Sockets;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span> <span style="color:#0000ff;">using</span> System.Net;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span> <span style="color:#0000ff;">using</span> System.Text;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span> <span style="color:#0000ff;">namespace</span> DeleetThis</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">partial</span> <span style="color:#0000ff;">class</span> Page : UserControl</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  18:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  19:</span>         <span style="color:#0000ff;">private</span> Socket socket;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  20:</span>         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">byte</span>[] transferBuffer;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  21:</span>         <span style="color:#0000ff;">private</span> SocketAsyncEventArgs sendEventArgs;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  22:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  23:</span>         <span style="color:#008000;">// contants</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  24:</span>         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">int</span> BUFFER_SIZE = 500;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  25:</span>         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">int</span> PORT = 4505;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courie
r New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  26:</span>         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> DnsEndPoint IP_END_POINT = <span style="color:#0000ff;">new</span> DnsEndPoint(Application.Current.Host.Source.DnsSafeHost, PORT);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  27:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  28:</span>         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">delegate</span> <span style="color:#0000ff;">void</span> SetTextCallback(String _text);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  29:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  30:</span>         <span style="color:#008000;">// initialize stuff</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  31:</span>         <span style="color:#0000ff;">public</span> Page()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  32:</span>         {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  33:</span>             InitializeComponent();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  34:</span>             socket = <span style="color:#0000ff;">new</span> Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  35:</span>             SocketAsyncEventArgs connectEventArgs = <span style="color:#0000ff;">new</span> SocketAsyncEventArgs();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  36:</span>             connectEventArgs.RemoteEndPoint = IP_END_POINT;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  37:</span>             connectEventArgs.Completed += <span style="color:#0000ff;">new</span> EventHandler&lt;SocketAsyncEventArgs&gt;(connectEventArgs_Completed);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  38:</span>             socket.ConnectAsync(connectEventArgs);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  39:</span>         }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  40:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  41:</span>         <span style="color:#008000;">// connection complete</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  42:</span>         <span style="color:#0000ff;">void</span> connectEventArgs_Completed(<span style="color:#0000ff;">object</span> sender, SocketAsyncEventArgs e)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  43:</span>         {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  44:</span>             sendEventArgs = <span style="color:#0000ff;">new</span> SocketAsyncEventArgs();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  45:</span>             sendEventArgs.RemoteEndPoint = IP_END_POINT;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  46:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  47:</span>             e.Completed -= <span style="color:#0000ff;">new</span> EventHandler&lt;SocketAsyncEventArgs&gt;(connectEventArgs_Completed);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  48:</span>             e.Completed += <span style="color:#0000ff;">new</span> EventHandler&lt;SocketAsyncEventArgs&gt;(receiveEventArgs_Completed);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  49:</span>             transferBuffer = <span style="color:#0000ff;">new</span> <span style="color:#0000ff;">byte</span>[BUFFER_SIZE];</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  50:</span>             e.SetBuffer(transferBuffer, 0, transferBuffer.Length);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', cou
rier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  51:</span>             socket.ReceiveAsync(e);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  52:</span>         }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  53:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  54:</span>         <span style="color:#008000;">// incoming data</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  55:</span>         <span style="color:#0000ff;">void</span> receiveEventArgs_Completed(<span style="color:#0000ff;">object</span> sender, SocketAsyncEventArgs e)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  56:</span>         {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  57:</span>             String a = Encoding.UTF8.GetString(transferBuffer, e.Offset, e.BytesTransferred);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  58:</span>             SetText(a);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  59:</span>             socket.ReceiveAsync(e);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  60:</span>         }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  61:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  62:</span>         <span style="color:#008000;">// this process is asynchronous so we need to invoke the ui thread to set the received text</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  63:</span>         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> SetText(String text)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  64:</span>         {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  65:</span>             <span style="color:#0000ff;">if</span> (<span style="color:#0000ff;">this</span>.Dispatcher.CheckAccess())</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  66:</span>                 receiveBox.Text += text;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  67:</span>             <span style="color:#0000ff;">else</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  68:</span>                 <span style="color:#0000ff;">this</span>.Dispatcher.BeginInvoke(<span style="color:#0000ff;">new</span> SetTextCallback(SetText), text);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  69:</span>         }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  70:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  71:</span>         <span style="color:#008000;">// data sending</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  72:</span>         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> sendButton_Click(<span style="color:#0000ff;">object</span> sender, RoutedEventArgs e)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  73:</span>         {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  74:</span>             List&lt;ArraySegment&lt;<span style="color:#0000ff;">byte</span>&gt;&gt; l = <span style="color:#0000ff;">new</span> List&lt;ArraySegment&lt;<span style="color:#0000ff;">byte</span>&gt;&gt;();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  75:</span>             l.Add(<span style="color:#0000ff;">new</span> ArraySegment&lt;<span style="color:#0000ff;">byte</span>&gt;(Encoding.UTF8.GetBytes(sendBox.Text + <span style="color:#006080;">"\n"</span>)));</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  76:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font
-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  77:</span>             sendEventArgs.BufferList = l;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  78:</span>             socket.SendAsync(sendEventArgs);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  79:</span>         }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  80:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  81:</span> }</pre>
</div>
</div>
<p><a href="http://pastie.caboo.se/182586">Here is the pastie.</a></p>
<p><u>Page.xaml:</u></p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">UserControl</span> <span style="color:#ff0000;">x:Class</span><span style="color:#0000ff;">="ChatClient.Page"</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>     <span style="color:#ff0000;">xmlns</span><span style="color:#0000ff;">="http://schemas.microsoft.com/client/2007"</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     <span style="color:#ff0000;">xmlns:x</span><span style="color:#0000ff;">="http://schemas.microsoft.com/winfx/2006/xaml"</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     <span style="color:#ff0000;">Width</span><span style="color:#0000ff;">="400"</span> <span style="color:#ff0000;">Height</span><span style="color:#0000ff;">="230"</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>     <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Grid</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="LayoutRoot"</span> <span style="color:#ff0000;">Background</span><span style="color:#0000ff;">="White"</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>         <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">StackPanel</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>             <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">ScrollViewer</span> <span style="color:#ff0000;">Height</span><span style="color:#0000ff;">="200"</span> <span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>                 <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="receiveBox"</span><span style="color:#0000ff;">/&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>             <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">ScrollViewer</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>             <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">StackPanel</span> <span style="color:#ff0000;">Orientation</span><span style="color:#0000ff;">="Horizontal"</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>                 <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">TextBox</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="sendBox"</span> <span style="color:#ff0000;">Height</span><span style="color:#0000ff;">="30"</span> <span style="color:#ff0000;">Width</span><span style="color:#0000ff;">="365"</span><span style="color:#0000ff;">/&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>                 <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Button</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="sendButton"</span> <span style="color:#ff0000;">Content</span><span style="color:#0000ff;">="Send"</span> <span style="color:#ff0000;">Click</span><span style="color:#0000ff;">="sendButton_Click"</span><span style="color:#0000ff;">/&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>             <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">StackPanel</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>         <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">StackPanel</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>     <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Grid</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span> <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">UserControl</span><span style="color:#0000ff;">&gt;</span></pre>
</div>
</div>
<p><a href="http://pastie.caboo.se/182585">Here is the pastie.</a></p>
<h5><u>Running the application:</u></h5>
<p>Now run this application in two different browser windows and whenever you type in one window the content of both windows should be updated :)</p>
<p><a href="http://allyourcodearebelongto.me/blog/wp-content/uploads/2008/04/image2.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="441" alt="image" src="http://allyourcodearebelongto.me/blog/wp-content/uploads/2008/04/image-thumb2.png" width="587" border="0"></a>&nbsp;</p>
<p>Download the source code:</p>
<ul>
<li><a href="http://cid-49208a72e4eb818c.skydrive.live.com/self.aspx/world/code/chat_server.rb">Ruby server</a></li>
<li><a href="http://cid-49208a72e4eb818c.skydrive.live.com/self.aspx/world/code/ChatClient.rar">Silverlight client</a></li>
</ul>
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:60c01296-59d8-4395-a333-8305d44473bf" style="display:inline;float:none;margin:0;padding:0;">del.icio.us Tags: <a href="http://del.icio.us/popular/C#" rel="tag">C#</a>,<a href="http://del.icio.us/popular/ruby" rel="tag">ruby</a>,<a href="http://del.icio.us/popular/silverlight" rel="tag">silverlight</a>,<a href="http://del.icio.us/popular/socket" rel="tag">socket</a>,<a href="http://del.icio.us/popular/visual%20studio%202008" rel="tag">visual studio 2008</a>,<a href="http://del.icio.us/popular/chat%20application" rel="tag">chat application</a></div>
]]></content:encoded>
			<wfw:commentRss>http://allyourcodearebelongto.me/blog/2008/04/17/creating-a-chat-application-using-socket-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Using Silverlight with Ruby on Rails</title>
		<link>http://allyourcodearebelongto.me/blog/2008/03/26/using-silverlight-with-rubyonrails/</link>
		<comments>http://allyourcodearebelongto.me/blog/2008/03/26/using-silverlight-with-rubyonrails/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 12:55:12 +0000</pubDate>
		<dc:creator>Gaurav</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[crud]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[mxml]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://techblogging.wordpress.com/2008/03/26/using-silverlight-with-rubyonrails/</guid>
		<description><![CDATA[In this post I will be showing a really simple example of creating a Silverlight frontend for a Rails backend. This is what I think will be a three part series comparing Silverlight with Flex.
The steps will be:

Creating a Rails application.
Creating a frontend for it in silverlight.
Creating a frontend for it in Flex.
Comparing the approaches [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will be showing a really simple example of creating a Silverlight frontend for a Rails backend. This is what I think will be a three part series comparing Silverlight with Flex.</p>
<p>The steps will be:</p>
<ol>
<li>Creating a Rails application.
<li>Creating a frontend for it in silverlight.
<li>Creating a frontend for it in Flex.
<li>Comparing the approaches taken in both the frontends. </li>
</ol>
<p> I will try to keep changes in the backend Rails application to a minimum.</p>
</p>
<p><span id="more-55"></span>
</p>
<h5><u>Creating a Rails Application</u></h5>
<div>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">F:\<span style="color:#0000ff;">&gt;</span>rails test
F:\<span style="color:#0000ff;">&gt;</span>cd test
F:\test<span style="color:#0000ff;">&gt;</span>ruby script\generate scaffold user name:string address:text
F:\test<span style="color:#0000ff;">&gt;</span>rake db:create
F:\test<span style="color:#0000ff;">&gt;</span>rake db:migrate
F:\test<span style="color:#0000ff;">&gt;</span>ruby script\server</pre>
</div>
<p>Before running the migrations add the following code in the first migration file (./db/migrate/001_create_users.rb) to create some initial data.&nbsp; So it should look like:</p>
<div>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">class</span> CreateUsers &lt; ActiveRecord::Migration
  def self.up
    create_table :users <span style="color:#0000ff;">do</span> |t|
      t.<span style="color:#0000ff;">string</span> :name
      t.text :address
      t.timestamps
    end

    User.create(:name=&gt; <span style="color:#006080;">"Gaurav"</span>, :address=&gt; <span style="color:#006080;">"Gaurav's address"</span>)
    User.create(:name=&gt; <span style="color:#006080;">"Rishav"</span>, :address=&gt; <span style="color:#006080;">"Rishav's address"</span>)
    User.create(:name=&gt; <span style="color:#006080;">"Bhavesh"</span>, :address=&gt; <span style="color:#006080;">"Bhavesh's address"</span>)
  end

  def self.down
    drop_table :users
  end
end</pre>
</div>
<p>&nbsp;</p>
<h5><u>Creating a new C# based Silverlight project</u></h5>
<p>&nbsp;</p>
<p>Open up Visual Studio 2008 (with Silverlight <a href="http://techblogging.wordpress.com/2008/03/05/silverlight-20-beta-1-now-available-and-10-version-ported-to-nokia-mobiles/">tools</a> installed. You can also download a trial version of Visual Studio 2008 from <a href="http://msdn2.microsoft.com/en-us/vstudio/products/aa700831.aspx">here</a>). And create a new project:</p>
<p><a href="http://allyourcodearebelongto.me/blog/wp-content/uploads/2008/03/vs-step1.png"><img style="border-width:0;" height="415" alt="vs_step1" src="http://allyourcodearebelongto.me/blog/wp-content/uploads/2008/03/vs-step1-thumb.png" width="609" border="0"></a></p>
<p><a href="http://allyourcodearebelongto.me/blog/wp-content/uploads/2008/03/vs-step2.png"><img style="border-width:0;" height="368" alt="vs_step2" src="http://allyourcodearebelongto.me/blog/wp-content/uploads/2008/03/vs-step2-thumb.png" width="439" border="0"></a></p>
<p>&nbsp;</p>
<p>Open the page.xaml file and add a ListBox to it. It should look like:</p>
<div>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">UserControl</span> <span style="color:#ff0000;">x:Class</span><span style="color:#0000ff;">="TestFrontEnd.Page"</span>
    <span style="color:#ff0000;">xmlns</span><span style="color:#0000ff;">="http://schemas.microsoft.com/client/2007"</span>
    <span style="color:#ff0000;">xmlns:x</span><span style="color:#0000ff;">="http://schemas.microsoft.com/winfx/2006/xaml"</span>
    <span style="color:#ff0000;">Width</span><span style="color:#0000ff;">="400"</span> <span style="color:#ff0000;">Height</span><span style="color:#0000ff;">="300"</span><span style="color:#0000ff;">&gt;</span>
    <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Grid</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="LayoutRoot"</span> <span style="color:#ff0000;">Background</span><span style="color:#0000ff;">="White"</span><span style="color:#0000ff;">&gt;</span>
        <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">ListBox</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="userList"</span> <span style="color:#ff0000;">Height</span><span style="color:#0000ff;">="200"</span><span style="color:#0000ff;">/&gt;</span>
    <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Grid</span><span style="color:#0000ff;">&gt;</span>
<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">UserControl</span><span style="color:#0000ff;">&gt;</span></pre>
</div>
<p>&nbsp;</p>
<p>Now when the server responds with xml, we will parse that using <a href="http://msdn2.microsoft.com/en-us/netframework/aa904594.aspx">Linq</a>. For that we need a User class that is like the user model on the Rails side. So it should have 3 fields:</p>
<ol>
<li>id
<li>name
<li>address </li>
</ol>
<p>It should look like:</p>
<div>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">namespace</span> TestFrontEnd {
    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> User {
        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> id { get; set; }
        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> name { get; set; }
        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> address { get; set; }
    }
}</pre>
</div>
<p>&nbsp;</p>
<p>To make things simpler I have created a HTTPService class that behaves something like the Flex based HTTPService class. <a href="http://pastie.caboo.se/170803">Here is the source</a> (too big to paste inline). Add it to your project. You will need to include System.Net assembly your project to to make it work. Its usage is quite simple.</p>
<div>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">HTTPService userIndexService = <span style="color:#0000ff;">new</span> HTTPService();
userIndexService.Url = <span style="color:#006080;">"http://localhost:3000/users.xml"</span>;
userIndexService.ServiceComplete += <span style="color:#0000ff;">new</span> HttpServiceCompleteEventHandler(userIndexService_ServiceComplete);
userIndexService.send();</pre>
</div>
<p>&nbsp;</p>
<p>You can also give the request method like:</p>
<div>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">userIndexService.Method = <span style="color:#006080;">"POST"</span>;</pre>
</div>
<p>&nbsp;</p>
<p>Now add an ObservableCollection to the Page class:</p>
<div>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">private</span> ObservableCollection&lt;User&gt; userListItems = <span style="color:#0000ff;">new</span> ObservableCollection&lt;User&gt;();</pre>
</div>
<p>&nbsp;</p>
<p>We will be using this for <a href="http://msdn2.microsoft.com/en-us/library/ms752347.aspx">databinding</a> with the ListBox to display all the users.</p>
<p>Add the System.Xml.Linq to your project. In the userIndexService_ServiceComplete event handler write:</p>
<div>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">void</span> userIndexService_ServiceComplete(HttpServiceCompleteEventArgs e) {
    XDocument users = XDocument.Parse(e.Response);
    User[] usersList = (from x <span style="color:#0000ff;">in</span> users.Descendants(<span style="color:#006080;">"user"</span>)
            select <span style="color:#0000ff;">new</span> User
            {
                id = <span style="color:#0000ff;">int</span>.Parse(x.Descendants(<span style="color:#006080;">"id"</span>).First().Value),
                name = x.Descendants(<span style="color:#006080;">"name"</span>).First().Value,
                address = x.Descendants(<span style="color:#006080;">"address"</span>).First().Value,
            }).ToArray();
    <span style="color:#0000ff;">foreach</span> (User user <span style="color:#0000ff;">in</span> usersList)
        userListItems.Add(user);
}</pre>
</div>
<p>&nbsp;</p>
<p>So when the service completes all the users will be filled in the ObserveableCollection. Now to bind it to the userList ListBox. In the constructor of the Page class write:</p>
<div>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">userList.DataContext = userListItems;</pre>
</div>
<p>&nbsp;</p>
<p>And modify the code for the userList ListBox to look like:</p>
<div>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">ListBox</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="userList"</span> <span style="color:#ff0000;">Height</span><span style="color:#0000ff;">="200"</span> <span style="color:#ff0000;">ItemsSource</span><span style="color:#0000ff;">="{Binding}"</span> <span style="color:#ff0000;">DisplayMemberPath</span><span style="color:#0000ff;">="name"</span> <span style="color:#0000ff;">/&gt;</span></pre>
</div>
<p>&nbsp;</p>
<p>Add a crossdomain.xml file to the rails project&#8217;s public folder:</p>
<div>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">&lt;?</span><span style="color:#800000;">xml</span> <span style="color:#ff0000;">version</span><span style="color:#0000ff;">="1.0"</span>?<span style="color:#0000ff;">&gt;</span>
<span style="color:#0000ff;">&lt;!</span><span style="color:#800000;">DOCTYPE</span> <span style="color:#ff0000;">cross-domain-policy</span> <span style="color:#ff0000;">SYSTEM</span> <span style="color:#0000ff;">"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"</span><span style="color:#0000ff;">&gt;</span>
<span style="color:#0000ff;">&lt;</span><span style="color:#800000;">cross-domain-policy</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">allow-access-from</span> <span style="color:#ff0000;">domain</span><span style="color:#0000ff;">="*"</span> <span style="color:#0000ff;">/&gt;</span>
<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">cross-domain-policy</span><span style="color:#0000ff;">&gt;</span></pre>
</div>
<p>We are basically allowing our Silverlight app to access the rails server. You won&#8217;t be requiring this file if the Rails server is serving the Silverlight application, but currently it is not the case.</p>
<p>Now when you run the code you should see:</p>
<p><a href="http://allyourcodearebelongto.me/blog/wp-content/uploads/2008/03/vs-step3.png"><img style="border-width:0;" height="416" alt="vs_step3" src="http://allyourcodearebelongto.me/blog/wp-content/uploads/2008/03/vs-step3-thumb.png" width="480" border="0"></a></p>
<p>Now I will add a few more lines of code to show the selected item in TextBox. Add/Update the following to page.xaml:</p>
<div>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">ListBox</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="userList"</span> <span style="color:#ff0000;">Height</span><span style="color:#0000ff;">="200"</span> <span style="color:#ff0000;">ItemsSource</span><span style="color:#0000ff;">="{Binding}"</span> <span style="color:#ff0000;">DisplayMemberPath</span><span style="color:#0000ff;">="name"</span> <span style="color:#ff0000;">SelectionChanged</span><span style="color:#0000ff;">="userList_SelectionChanged"</span><span style="color:#0000ff;">/&gt;</span>
<span style="color:#0000ff;">&lt;</span><span style="color:#800000;">StackPanel</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="controls"</span><span style="color:#0000ff;">&gt;</span>
    <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">TextBox</span> <span style="color:#ff0000;">Text</span><span style="color:#0000ff;">="{Binding name, Mode=Twoway}"</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="userName"</span><span style="color:#0000ff;">/&gt;</span>
    <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">TextBox</span> <span style="color:#ff0000;">Text</span><span style="color:#0000ff;">="{Binding address, Mode=Twoway}"</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="userAddress"</span><span style="color:#0000ff;">/&gt;</span>
<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">StackPanel</span><span style="color:#0000ff;">&gt;</span></pre>
</div>
<p>The first TextBox is showing name and second is showing the password. The binding mode is set to TwoWay so that the changes in TextBox are automatically to the userListItems.</p>
<p>Add the corresponding event handler to Page class:</p>
<div>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> userList_SelectionChanged(<span style="color:#0000ff;">object</span> sender, SelectionChangedEventArgs e) {
    controls.DataContext = userList.SelectedItem <span style="color:#0000ff;">as</span> User;
}</pre>
</div>
<p>&nbsp;</p>
<p>Now when you run the code you should see:</p>
<p><a href="http://allyourcodearebelongto.me/blog/wp-content/uploads/2008/03/image6.png"><img style="border-width:0;" height="423" alt="image" src="http://allyourcodearebelongto.me/blog/wp-content/uploads/2008/03/image-thumb6.png" width="481" border="0"></a></p>
<p>Download the code upto this point:</p>
<ul>
<li><a href="http://cid-49208a72e4eb818c.skydrive.live.com/self.aspx/world/code/test.rar">Rails code</a>
<li><a href="http://cid-49208a72e4eb818c.skydrive.live.com/self.aspx/world/code/TestFrontEnd.rar">Silverlight code</a> </li>
</ul>
<p>&nbsp;</p>
<h5>&nbsp;<u>Implementing the full <a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> :</u></h5>
<p>&nbsp;</p>
<p>Firstly I willl be doing a bit of refactoring. Move the xml parsing code using Linq to the User class. So it should now look like:</p>
<div>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> User {
    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> id { get; set; }
    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> name { get; set; }
    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> address { get; set; }

    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> User[] users_from_xml(String xml_string){
        XDocument users = XDocument.Parse(xml_string);
        <span style="color:#0000ff;">return</span> (from x <span style="color:#0000ff;">in</span> users.Descendants(<span style="color:#006080;">"user"</span>)
            select <span style="color:#0000ff;">new</span> User
            {
                id = <span style="color:#0000ff;">int</span>.Parse(x.Descendants(<span style="color:#006080;">"id"</span>).First().Value),
                name = x.Descendants(<span style="color:#006080;">"name"</span>).First().Value,
                address = x.Descendants(<span style="color:#006080;">"address"</span>).First().Value,
            }).ToArray();
    }

    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> User user_from_xml(String xml_string) {
        <span style="color:#0000ff;">return</span> users_from_xml(xml_string).First();
    }
}</pre>
</div>
<p>&nbsp;</p>
<p>Change the Page class to:</p>
<div>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">using</span> System;
<span style="color:#0000ff;">using</span> System.Collections.Generic;
<span style="color:#0000ff;">using</span> System.Linq;
<span style="color:#0000ff;">using</span> System.Windows;
<span style="color:#0000ff;">using</span> System.Windows.Controls;
<span style="color:#0000ff;">using</span> System.Windows.Documents;
<span style="color:#0000ff;">using</span> System.Windows.Input;
<span style="color:#0000ff;">using</span> System.Windows.Media;
<span style="color:#0000ff;">using</span> System.Windows.Media.Animation;
<span style="color:#0000ff;">using</span> System.Windows.Shapes;
<span style="color:#0000ff;">using</span> System.Collections.ObjectModel;
<span style="color:#0000ff;">using</span> System.Xml.Linq;

<span style="color:#0000ff;">namespace</span> TestFrontEnd {
    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">partial</span> <span style="color:#0000ff;">class</span> Page : UserControl {
        <span style="color:#0000ff;">private</span> ObservableCollection&lt;User&gt; userListItems = <span style="color:#0000ff;">new</span> ObservableCollection&lt;User&gt;();

        <span style="color:#0000ff;">private</span> HTTPService userIndexService;
        <span style="color:#0000ff;">private</span> HTTPService userCreateService;
        <span style="color:#0000ff;">private</span> HTTPService userUpdateService;
        <span style="color:#0000ff;">private</span> HTTPService userDeleteService;

        <span style="color:#0000ff;">public</span> Page() {
            InitializeComponent();
            <span style="color:#008000;">// setting the databinding</span>
            userList.DataContext = userListItems;
            controls.DataContext = <span style="color:#0000ff;">new</span> User();

            <span style="color:#008000;">// service to get all te users form the server</span>
            userIndexService = <span style="color:#0000ff;">new</span> HTTPService();
            userIndexService.Url = <span style="color:#006080;">"http://localhost:3000/users.xml"</span>;
            userIndexService.ServiceComplete += <span style="color:#0000ff;">new</span> HttpServiceCompleteEventHandler(userIndexService_ServiceComplete);
            userIndexService.send();

            <span style="color:#008000;">// create a new user</span>
            userCreateService = <span style="color:#0000ff;">new</span> HTTPService();
            userCreateService.Url = <span style="color:#006080;">"http://localhost:3000/users.xml"</span>;
            userCreateService.Method = <span style="color:#006080;">"POST"</span>;
            userCreateService.ServiceComplete += <span style="color:#0000ff;">new</span> HttpServiceCompleteEventHandler(userCreateService_ServiceComplete);

            <span style="color:#008000;">// update a user, we will not be trapping the results</span>
            userUpdateService = <span style="color:#0000ff;">new</span> HTTPService();
            userUpdateService.Method = <span style="color:#006080;">"POST"</span>;

            <span style="color:#008000;">// delete a user</span>
            userDeleteService = <span style="color:#0000ff;">new</span> HTTPService();
            userDeleteService.Method = <span style="color:#006080;">"POST"</span>;
        }

        <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> _userList_SelectionChanged(<span style="color:#0000ff;">object</span> sender, SelectionChangedEventArgs e) {
            controls.DataContext = userList.SelectedItem <span style="color:#0000ff;">as</span> User;
        }

        <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> userIndexService_ServiceComplete(HttpServiceCompleteEventArgs e) {
            <span style="color:#0000ff;">foreach</span> (User user <span style="color:#0000ff;">in</span> User.users_from_xml(e.Response))
                userListItems.Add(user);
        }
        <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> userCreateService_ServiceComplete(HttpServiceCompleteEventArgs e) {
            userListItems.Add(User.user_from_xml(e.Response));
        }

        <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> createButton_Click(<span style="color:#0000ff;">object</span> sender, RoutedEventArgs e) {
            userCreateService.send(String.Format(<span style="color:#006080;">"{0}={1}&amp;{2}={3}"</span>, <span style="color:#006080;">"user[name]"</span>, userName.Text, <span style="color:#006080;">"user[address]"</span>, userAddress.Text));
        }

        <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> updateButton_Click(<span style="color:#0000ff;">object</span> sender, RoutedEventArgs e) {
            User _selectedUser = userList.SelectedItem <span style="color:#0000ff;">as</span> User;
            userUpdateService.Url = <span style="color:#006080;">"http://localhost:3000/users/"</span> + _selectedUser.id.ToString() + <span style="color:#006080;">".xml"</span>;
            userUpdateService.send(String.Format(<span style="color:#006080;">"{0}={1}&amp;{2}={3}&amp;{4}={5}"</span>, <span style="color:#006080;">"user[name]"</span>, userName.Text, <span style="color:#006080;">"user[address]"</span>, userAddress.Text, <span style="color:#006080;">"_method"</span>, <span style="color:#006080;">"PUT"</span>));
            userListItems[userList.SelectedIndex] = _selectedUser;
        }

        <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> deleteButton_Click(<span style="color:#0000ff;">object</span> sender, RoutedEventArgs e) {
            User _selectedUser = userList.SelectedItem <span style="color:#0000ff;">as</span> User;
            userDeleteService.Url = <span style="color:#006080;">"http://localhost:3000/users/"</span> + _selectedUser.id.ToString() + <span style="color:#006080;">".xml"</span>;
            userDeleteService.send(String.Format(<span style="color:#006080;">"{0}={1}"</span>, <span style="color:#006080;">"_method"</span>, <span style="color:#006080;">"DELETE"</span>));
            userListItems.Remove(_selectedUser);
        }

    }
}
</pre>
</div>
<p>&nbsp;</p>
<p>To understand the specific parameters to the &#8220;send()&#8221; method of the HTTPService class you will need a little bit of understanding of how REST is implemented in Rails and how parameters are passed to a url, which is out of scope of this blog post.</p>
<p>&nbsp;</p>
<p>Change Page.xaml to:</p>
<div>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">UserControl</span> <span style="color:#ff0000;">x:Class</span><span style="color:#0000ff;">="TestFrontEnd.Page"</span>
    <span style="color:#ff0000;">xmlns</span><span style="color:#0000ff;">="http://schemas.microsoft.com/client/2007"</span>
    <span style="color:#ff0000;">xmlns:x</span><span style="color:#0000ff;">="http://schemas.microsoft.com/winfx/2006/xaml"</span>
    <span style="color:#ff0000;">Width</span><span style="color:#0000ff;">="400"</span> <span style="color:#ff0000;">Height</span><span style="color:#0000ff;">="300"</span><span style="color:#0000ff;">&gt;</span>
    <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Grid</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="LayoutRoot"</span> <span style="color:#ff0000;">Background</span><span style="color:#0000ff;">="White"</span><span style="color:#0000ff;">&gt;</span>
        <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">StackPanel</span> <span style="color:#ff0000;">Orientation</span><span style="color:#0000ff;">="Vertical"</span><span style="color:#0000ff;">&gt;</span>
            <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">ListBox</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="userList"</span> <span style="color:#ff0000;">ItemsSource</span><span style="color:#0000ff;">="{Binding}"</span> <span style="color:#ff0000;">DisplayMemberPath</span><span style="color:#0000ff;">="name"</span> <span style="color:#ff0000;">SelectionChanged</span><span style="color:#0000ff;">="_userList_SelectionChanged"</span> <span style="color:#ff0000;">Height</span><span style="color:#0000ff;">="200"</span><span style="color:#0000ff;">/&gt;</span>
            <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">StackPanel</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="controls"</span><span style="color:#0000ff;">&gt;</span>
                <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">TextBox</span> <span style="color:#ff0000;">Text</span><span style="color:#0000ff;">="{Binding name, Mode=Twoway}"</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="userName"</span><span style="color:#0000ff;">/&gt;</span>
                <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">TextBox</span> <span style="color:#ff0000;">Text</span><span style="color:#0000ff;">="{Binding address, Mode=Twoway}"</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="userAddress"</span><span style="color:#0000ff;">/&gt;</span>
            <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">StackPanel</span><span style="color:#0000ff;">&gt;</span>
            <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">StackPanel</span> <span style="color:#ff0000;">Orientation</span><span style="color:#0000ff;">="Horizontal"</span><span style="color:#0000ff;">&gt;</span>
                <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Button</span> <span style="color:#ff0000;">Content</span><span style="color:#0000ff;">="Create"</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="createButton"</span> <span style="color:#ff0000;">Click</span><span style="color:#0000ff;">="createButton_Click"</span><span style="color:#0000ff;">/&gt;</span>
                <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Button</span> <span style="color:#ff0000;">Content</span><span style="color:#0000ff;">="Update"</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="updateButton"</span> <span style="color:#ff0000;">Click</span><span style="color:#0000ff;">="updateButton_Click"</span><span style="color:#0000ff;">/&gt;</span>
                <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Button</span> <span style="color:#ff0000;">Content</span><span style="color:#0000ff;">="Delete"</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="deleteButton"</span> <span style="color:#ff0000;">Click</span><span style="color:#0000ff;">="deleteButton_Click"</span><span style="color:#0000ff;">/&gt;</span>
            <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">StackPanel</span><span style="color:#0000ff;">&gt;</span>
            <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="trace"</span> <span style="color:#0000ff;">/&gt;</span>
        <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">StackPanel</span><span style="color:#0000ff;">&gt;</span>
    <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Grid</span><span style="color:#0000ff;">&gt;</span>
<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">UserControl</span><span style="color:#0000ff;">&gt;</span>
</pre>
</div>
<p>&nbsp;</p>
<p>This is how it looks like now:</p>
<p><a href="http://allyourcodearebelongto.me/blog/wp-content/uploads/2008/03/image7.png"><img style="border-width:0;" height="423" alt="image" src="http://allyourcodearebelongto.me/blog/wp-content/uploads/2008/03/image-thumb7.png" width="481" border="0"></a></p>
<p>So this is full CRUD implementation using Silverlight as frontend.</p>
<p>This is not the most optimal way to implement CRUD it is very easy to understand. It also should be noted that I haven&#8217;t added error checking of any type in the code and there is a lot of code repetition. But I guess that could be improved upon further once the most simple scenario is implemented. My style of coding is &#8220;First make it work and then optimize it&#8221;, and as I have mentioned it before it is certainly not the most optimized way to code but it sure works :)</p>
<p>One microsoft releases better databinding capabilities in controls and some simpler classes for HTTP based communication, this code would be much more simpler.</p>
<p>Full code for this aplication can be downloaded from:</p>
<li><a href="http://cid-49208a72e4eb818c.skydrive.live.com/self.aspx/world/code/test.rar">Rails code</a>
<li><a href="http://cid-49208a72e4eb818c.skydrive.live.com/self.aspx/world/code/TestFrontEnd2.rar">Silverlight code</a></li>
<p>&nbsp;</p>
<div class="wlWriterSmartContent" id="5ce5ff6c-9474-4531-909c-9f79bda9013e" style="display:inline;margin:0;padding:0;">del.icio.us Tags: <a href="http://del.icio.us/popular/adobe" rel="tag">adobe</a>,<a href="http://del.icio.us/popular/C#" rel="tag">C#</a>,<a href="http://del.icio.us/popular/crud" rel="tag">crud</a>,<a href="http://del.icio.us/popular/flex" rel="tag">flex</a>,<a href="http://del.icio.us/popular/microsoft" rel="tag">microsoft</a>,<a href="http://del.icio.us/popular/rails" rel="tag">rails</a>,<a href="http://del.icio.us/popular/ruby%20on%20rails" rel="tag">ruby on rails</a>,<a href="http://del.icio.us/popular/silverlight" rel="tag">silverlight</a>,<a href="http://del.icio.us/popular/xaml" rel="tag">xaml</a></div>
]]></content:encoded>
			<wfw:commentRss>http://allyourcodearebelongto.me/blog/2008/03/26/using-silverlight-with-rubyonrails/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

