<?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>Bee Eee Blog &#187; networking</title>
	<atom:link href="http://blog.bee-eee.com/category/networking/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bee-eee.com</link>
	<description>-- C# hints and tips</description>
	<lastBuildDate>Wed, 23 Dec 2009 19:00:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>c# Getting your machine&#8217;s IP addresses.</title>
		<link>http://blog.bee-eee.com/2009/03/17/c-getting-your-machines-ip-addresses/</link>
		<comments>http://blog.bee-eee.com/2009/03/17/c-getting-your-machines-ip-addresses/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 15:35:30 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c# coding GUI]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[networking]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/?p=69</guid>
		<description><![CDATA[Here is the simple way to get all of the IP addresses for you machine. This code filters out everything but IPv4 address, but to truly get everything just remove the if statement. string hostName = Dns.GetHostName(); var addrs = Dns.GetHostAddresses(hostName); bool hasIP = false; for (int i = 0; i < addrs.Length; i++) { [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the simple way to get all of the IP addresses for you machine.  This code filters out everything but IPv4 address, but to truly get everything just remove the if statement.</p>
<pre class="code">
string hostName = Dns.GetHostName();
var addrs = Dns.GetHostAddresses(hostName);
bool hasIP = false;
for (int i = 0; i < addrs.Length; i++)
{
    IPAddress addr = addrs[i];
    if (addr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
    {
        si.DataIP = addr.ToString();
        hasIP = true;
        break;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2009/03/17/c-getting-your-machines-ip-addresses/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>c# non-blocking sockets</title>
		<link>http://blog.bee-eee.com/2008/09/15/c-non-blocking-sockets/</link>
		<comments>http://blog.bee-eee.com/2008/09/15/c-non-blocking-sockets/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 17:13:43 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[networking]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/09/15/c-non-blocking-sockets/</guid>
		<description><![CDATA[There doesn&#8217;t seem to be much written on blocking socket with c#.  So I&#8217;ll write a very short piece, and I&#8217;ll only concentrate on client sockets. Creating a socket is easy here is how: using System.Net.Sockets; //... // Creating a connection Socket client; client = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ); client.Connect(hostName, port); client.Blocking = [...]]]></description>
			<content:encoded><![CDATA[<p>There doesn&#8217;t seem to be much written on blocking socket with c#.  So I&#8217;ll write a very short piece, and I&#8217;ll only concentrate on client sockets.</p>
<p>Creating a socket is easy here is how:</p>
<pre class="code">
using System.Net.Sockets;

//...

// Creating a connection
Socket client;
client = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
client.Connect(hostName, port);
client.Blocking = false; // This needs to be done after Connect or it will error out.</pre>
<p>Here&#8217;s how to write data to the socket</p>
<pre class="code">
// Writing information to the socket
byte[] buffer = ASCIIEncoding.ASCII.GetBytes(messageText);
foreach (byte c in buffer)
{
	SocketError err = SocketError.WouldBlock;
	// need to try again if the socket would have blocked
	while ( err == SocketError.WouldBlock )
	{
		// this version of Send must be used or an exception would be thrown, which I feel is a pain
		// to deal with -- this way you can see handle the error appropriately.
		client.Send(buffer, 0, 1, SocketFlags.None, out err );
	}

	if ( err != SocketError.Success )
	{
		// handle error
		break;
	}
}</pre>
<p>And now code to read from a non-blocking socket</p>
<pre class="code">
// Reading from the socket
// this loop keeps going until there is a socket error or a '0' byte is read which
// in this example marks the end of the message
System.Text.StringBuilder message = new System.Text.StringBuilder();
while ( true )
{
	byte c = 0;
	int bytesRead;
	SocketError err;
	// read a character.
	bytesRead = client.Receive(buffer, 0, 1, SocketFlags.None, out err );
	// checking what happened
	if ( SocketError.Success == err )
	{
		// read a byte!  Let's process it
		if ( bytesRead &gt; 0 )
		{
			// found a null character -- in this case it makes the end of a message.
			if (c == 0)
			{
				// null terminated message received
				break;
			}
			else
				message.Append((char)c);
			}
		}
	}
	else if ( SocketError.WouldBlock != err )
	{
		break;
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/09/15/c-non-blocking-sockets/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
