<?xml version="1.0" encoding="UTF-8"?><!--RSS generated by Windows SharePoint Services V3 RSS Generator on 06/02/2012 16:56:08--><?xml-stylesheet type="text/xsl" href="/blog/_layouts/RssXslt.aspx?List=98d5c6c7-5808-4bc4-a33a-5cd0f6350ed4" version="1.0"?><rss version="2.0"><channel><title>Blog</title><link>http://www.dotnetsolutions.co.uk/blog</link><description>RSS feed for the Posts list.</description><lastBuildDate>Mon, 06 Feb 2012 16:56:08 GMT</lastBuildDate><generator>SharePoint CKS:EBE</generator><ttl>60</ttl><image><title>Blog</title><url>http://www.dotnetsolutions.co.uk/blog/_layouts/images/homepage.gif</url><link>http://www.dotnetsolutions.co.uk/blog</link></image><item><title>Agile is not just Software Development</title><link>http://www.dotnetsolutions.co.uk/blog/archive/2010/11/22/agile-is-not-just-software-development/</link><guid isPermaLink="False">/blog/archive/2010/11/22/agile-is-not-just-software-development/</guid><description><![CDATA[<div class="ExternalClassDB89942A7E4941E7B85EAC551D289AD3"><p>At Dot Net Solutions, we are ardent advocates of the Agile philosophy. In fact we want to get t-shirts made with Eat Agile, Sleep Agile, Drink Coffee. Not that we need the caffeine, we’re connoisseurs don’t you know!</p>  <p>The Agile umbrella is a way of working – a set of principles to advocate and emulate. There are many ways of achieving this philosophy: Lean, XP, and most people who have heard about Agile have probably heard about Scrum. Scrum is our chosen flavour for our projects, and it can be applied to most areas of life. It works from development teams up to enterprise organisations. This doesn’t mean it’s a magic bullet – it’s not going to solve everything in one go and it’s not going to do the work for you.</p>  <p>One thing I always take away from Scrum is the principle of using things appropriately. There are lots of misconceptions about Agile and its associated frameworks – things like “no documentation” and “no planning”. These are false! To be fair someone could probably get along without these thinking they are living the Agile dream, but to be honest they are setting themselves up for failure.</p>  <p>What is more important is choose appropriate options. Include documentation; just make sure it’s documentation for a specific purpose, and not superfluous record keeping or speculation. And definitely plan! Think about the short and medium term, don’t get bogged down with planning the long term in a huge amount of detail that will inevitably change. Also think about how you work. This means choosing the appropriate tools.</p>  <p>We wanted to start tracking the general stuff that we had to do as an office and as an organisation – you know: the re-supplies, upgrades and improvements we are constantly rolling out in order to be more productive as a company. Of course, using Scrum every day our first inclination was to use Scrum for this purpose as well. We set up a wall in the Staff room, populated it with backlog items and then set to work working through sprints lasting 4 weeks.</p>  <p>2 Sprints in we did what every good Scrum team does – we inspect and we adapt. When we looked back on the last sprint it dawned on me that we were not living up to the Scrum framework – we had become a “Scrum But” team. You know, those teams that when you ask them what methodology they use they reply “Oh it’s Scrum, but we don’t do retrospectives” or “We use Scrum, but we don’t do daily standup meetings.”</p>  <p>We had fallen into the same trap! This is why I love retrospectives – they give insight into where things are not working so that you can adapt your approach. Our conclusions in this case? Perhaps Scrum isn’t the right tool to use. So we have looked to another sister approach under the Agile umbrella – Kanban. This is an approach that still uses a task board / wall to view items moving through the pipeline, so that you can identify holdups and blockages visually. We think we chose the appropriate tool for the job; it’s suiting us better, but I am sure we’ll be adapting to improve things again in the future! </p>  <p>It goes to show that by keeping to the principle, and being open to change, you can apply Agile to all walks of life – it’s a way of business that’s constantly growing and evolving. Agile allows us to deliver cutting-edge high-quality software solutions to our customers quickly. Talk to us to find out what we could do for your business.</p>  <p>Author: Dan Woodward</p>  <p><a href="http://twitter.com/deedubbleyoo"><img style="background-image:none;border-bottom:0px;border-left:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px" title="twiticon" border="0" alt="twiticon" src="http://www.dotnetsolutions.co.uk/blog/Lists/Posts/Attachments/136/twiticon_7_06940327.jpg" width="18" height="18"></a> <a href="http://twitter.com/deedubbleyoo" target="_blank">Follow me!</a></p>  <p><a href="http://twitter.com/share?url= http://www.dotnetsolutions.co.uk/blog/archive/2010/11/22/agile-is-not-just-software-development/&amp;via=dotnetsolutions&amp;related=deedubbleyoo&amp;text=Agile in Work"><img style="background-image:none;border-bottom:0px;border-left:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px" title="twiticon" border="0" alt="twiticon" src="http://www.dotnetsolutions.co.uk/blog/Lists/Posts/Attachments/136/twiticon_6_06940327.jpg" width="18" height="18"></a> <a href="http://twitter.com/share?url= http://www.dotnetsolutions.co.uk/blog/archive/2010/11/22/agile-is-not-just-software-development/&amp;via=dotnetsolutions&amp;related=deedubbleyoo&amp;text=Agile in Work" target="_blank">Share this post on Twitter</a></p></div>]]></description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">DOTNETSOL\SharepointSA</dc:creator><pubDate>Mon, 22 Nov 2010 13:47:40 GMT</pubDate></item><item><title>The Job Application Application</title><link>http://www.dotnetsolutions.co.uk/blog/archive/2010/11/08/the-job-application-application/</link><guid isPermaLink="False">/blog/archive/2010/11/08/the-job-application-application/</guid><description><![CDATA[<div class="ExternalClass316C08FB407E4B3F94FBB9B6301ADA12"><h3>Problem statement</h3>  <p>Lately, we have been recruiting developers and architects at all levels. Our recruitment process comprises a review of a prospective employee’s CV, followed by a brief telephone interview with a few simple questions designed to eliminate the disastrous, dishonest or downright delusional applicants. The few people who make it past that stage are invited into the office for a good, in-depth, face-to-face interview where we talk tech and write code on whiteboards.</p>  <p>This process has been unsatisfying. Unfortunately, we get far too many CVs from people saying they have 8 years experience in .NET programming who are then unable to describe garbage collection, or explain what the IDisposable interface is for. Clearly that is acceptable for some companies, but we expect a little more. Not a lot, just some sign that you’ve taken the slightest little bit of interest in the platform you claim to have been developing on for a quarter of your life.</p>  <p>So I was pondering how we could better filter the CVs, and wishing that they could be statically typed and checked by a compiler, when it occurred to me that they can: if we ask people to write their CV in C#.</p>  <h3>The solution</h3>  <p>I’ve created a project with an assembly that exposes two interfaces – IResume and IEmploymentHistoryItem – and a smattering of supporting classes and enums, such as Skill and Proficiency.</p>  <p>I’ve used Sandcastle to document these interfaces and classes, and we are putting the documentation on our website.</p>  <p>Starting soon, if you would like to apply for a job at Dot Net Solutions – and trust me, it’s a fantastic place to work – then you will only be able to send us your CV in the form of a Visual Studio 2010 solution containing a project which implements the interfaces. We’ll take a quick look through the code to check for malicious intent, then we’ll build it. If it doesn’t build, we won’t call you. Then, the resulting assembly will be loaded in a WPF application which, if you have implemented the interfaces correctly, will display your CV and let us print it. If we can’t view or print your CV, we won’t call you.</p>  <p>If we can build your solution and print your CV, then we will call you, we’ll have a very quick chat and, if we have an opening, we’ll get you in for an interview.</p>  <p>Oh, and don’t get your friend to write the application for you, because we’ll find out.</p>  <p>I’m currently trialling this process with a friendly guinea pig; if that goes smoothly then we’ll roll it out more widely very soon.</p></div>]]></description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">DOTNETSOL\SharepointSA</dc:creator><pubDate>Mon, 08 Nov 2010 13:52:26 GMT</pubDate></item><item><title>Socket Connect - a word of warning</title><link>http://www.dotnetsolutions.co.uk/blog/archive/2010/09/09/socket-connect-a-word-of-warning/</link><guid isPermaLink="False">/blog/archive/2010/09/09/socket-connect-a-word-of-warning/</guid><description><![CDATA[<div class="ExternalClass53BCCA2969DC45588FE3457682923AEC">
<p>This is the third in a series of articles describing the issues we have encountered when using Sockets in the .Net Micro Framework and highlights quite an acute problem. </p>
<p><b>Symptoms</b></p>
<p>You are attempting to connect to a remote endpoint over TCP. Your code looks not too dissimilar to this:</p>
<div class="csharpcode">
<pre class="alt"><span class="kwrd">public</span> <span class="kwrd">void</span> SendData(IPAddress address, <span class="kwrd">int</span> port)</pre>
<pre>{</pre>
<pre class="alt">    IPEndPoint endpoint = <span class="kwrd">new</span> IPEndPoint(address, port);</pre>
<pre>    <span class="kwrd">using</span> (var socket = <span class="kwrd">new</span> Socket(AddressFamily.InterNetwork</pre>
<pre class="alt">                        , SocketType.Stream, ProtocolType.Tcp))</pre>
<pre>    {</pre>
<pre class="alt">        socket.Connect(endpoint);</pre>
<pre>        <span class="rem">/*communicaton code </span></pre>
<pre class="alt"><span class="rem"> *removed to keep </span></pre>
<pre><span class="rem"> *example terse*/</span></pre>
<pre class="alt">        socket.Close();</pre>
<pre>    }</pre>
<pre class="alt">}</pre>
</div>
<style>
.ExternalClassDE55195651F246F1A14C9017A249FAE3 .csharpcode, .ExternalClassDE55195651F246F1A14C9017A249FAE3 .csharpcode pre
{font-size:small;color:black;font-family:consolas, &quot;Courier New&quot;, courier, monospace;background-color:#ffffff;}
.ExternalClassDE55195651F246F1A14C9017A249FAE3 .csharpcode pre
{margin:0em;}
.ExternalClassDE55195651F246F1A14C9017A249FAE3 .csharpcode .rem
{color:#008000;}
.ExternalClassDE55195651F246F1A14C9017A249FAE3 .csharpcode .kwrd
{color:#0000ff;}
.ExternalClassDE55195651F246F1A14C9017A249FAE3 .csharpcode .str
{color:#006080;}
.ExternalClassDE55195651F246F1A14C9017A249FAE3 .csharpcode .op
{color:#0000c0;}
.ExternalClassDE55195651F246F1A14C9017A249FAE3 .csharpcode .preproc
{color:#cc6633;}
.ExternalClassDE55195651F246F1A14C9017A249FAE3 .csharpcode .asp
{background-color:#ffff00;}
.ExternalClassDE55195651F246F1A14C9017A249FAE3 .csharpcode .html
{color:#800000;}
.ExternalClassDE55195651F246F1A14C9017A249FAE3 .csharpcode .attr
{color:#ff0000;}
.ExternalClassDE55195651F246F1A14C9017A249FAE3 .csharpcode .alt
{background-color:#f4f4f4;width:100%;margin:0em;}
.ExternalClassDE55195651F246F1A14C9017A249FAE3 .csharpcode .lnum
{color:#606060;}
</style>
<p>This code has worked absolutely fine for a while now without any defects. All of a sudden your application now appears to hang indefinitely every time it tries to communicate using Sockets. You step through your code line by line in Visual Studio and it turns out that the troublesome line is the call to <a href="http://msdn.microsoft.com/en-us/library/cc531624.aspx">Socket.Connect()</a>. When you call this method it does not return; even if you wait for 2-3 minutes; but what has changed? It always used to work.</p>
<p>Not sure that this is correct. If the service is down then it should connect using the Socket Connect, but will return an exception and 500 error code. The problem with the Socket Connect is that if the network connectivity is removed. I.e. if there is no network, then the Connect “never” returns.</p>
<p>What’s actually happening here? Why did we not get an exception? Surely it would have timed out after 3 minutes?</p>
<p>It turns out that Socket.Connect does not actually timeout; at least it doesn’t do it for an interval that will be of any use to you or your application. We run a test for more than 2 hours. </p>
<p><b>Conclusion</b></p>
<p>Knowing this odd nuance of the .Net Micro Framework highlights the need to think very carefully about the architecture of your application. </p>
<p>· Is it wise to run your Socket code on the same thread as any other functionality? <br>
Would you be potentially blocking time sensitive operations? Probably not a good design to use this model an event model would be much better.</p>
<p>· When network is reconnected, the connection that was in progress will error. So you need to manage this error and retry etc</p>
<p>· If no exceptions are being thrown how do detect these events and are they important to you and your application? </p>
<p>· How can I mitigate against the chances of this happening in the first place? <br>
For example you should consider using DNS to delegate the responsibility of identifying which IP your application should be connecting to. That can optimize for the edge case scenario where your server is down and you need to move to a new (secondary) server in a hurry.</p>
<p>This was a bug identified in the .Net Micro Framework 3.0 and due to rather unfortunate conflicts between the version 4 release plan and when we identified the bug the same is true for Microsoft’s latest offering as well. We can’t comment on MS’s release plan. <a name="_GoBack"></a></p>
<p>This was one of several interesting issues encountered when working with Sockets in the .Net Micro Framework. If this was interesting / relevant for you then you might also want to consider reading the following articles:</p>
<ul>
    <li><a href="http://www.dotnetsolutions.co.uk/blog/archive/2010/09/02/linger-error" target="_blank">.Net Micro Framework Sockets: A lingering smell</a> </li>
    <li><a href="http://www.dotnetsolutions.co.uk/blog/archive/2010/09/06/socket-timing-problems" target="_blank">.Net Micro Framework Sockets: Intermittent performance</a> </li>
</ul>
<p>Author: Gavin Osborn <br>
<a href="http://twitter.com/gavinosborn" target="_blank"><img alt="" border="0" src="http://a4.twimg.com/images/favicon.gif">@gavinosborn</a> <br>
<br>
<a href="http://twitter.com/share?url=http://www.dotnetsolutions.co.uk/blog/archive/2010/09/09//socket-connect-a-word-of-warning/&amp;via=dotnetsolutions&amp;related=gavinosborn&amp;text=Socket Connect - a word of warning" target="_blank"><img alt="" border="0" src="http://a4.twimg.com/images/favicon.gif">Tweet</a></p>

</div>]]></description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">DOTNETSOL\Marcus</dc:creator><pubDate>Thu, 09 Sep 2010 14:38:00 GMT</pubDate><category domain="http://www.dotnetsolutions.co.uk/blog/archive/tags/Micro Framework/">Micro Framework</category></item><item><title>Socket Timing Problems</title><link>http://www.dotnetsolutions.co.uk/blog/archive/2010/09/06/socket-timing-problems/</link><guid isPermaLink="False">/blog/archive/2010/09/06/socket-timing-problems/</guid><description><![CDATA[<div class="ExternalClassD8F1B220D4304625AF92166AACC5AF4C">
<p>In a previous blog post I described the <a href="http://www.dotnetsolutions.co.uk/blog/archive/2010/09/02/linger-error" target="_blank">Linger error</a> that we were running into from time to time and how you can mitigate against this by setting the ‘Linger’ option on the socket. This was the first of several issues we identified when working with Sockets in the .Net Micro Framework 3.0.</p>
<p>The next challenge we faced was to do with intermittent performance problems when communicating over HTTPS.</p>
<p><b>Example: The Socket Client Demo</b></p>
<p>We had noticed that the time it took for our application to communicate with HTTP and HTTPS endpoints (even on our internal network) seemed to vary greatly. These requests were consistent in both size and complexity yet some would take &lt;1s and others appeared to take 10s.</p>
<p>To highlight this problem we used the ‘SocketClient’ demo application provided as part of the Micro Framework 3.0 SDK. This demo application makes a HTTP GET request to a given endpoint out on the internet and reads the response. Choosing this sample application for our testing allowed us to rule out the complexities in our own project as the source of the problem.</p>
<p>We made a small change to the code so that it would tell us how long it took to make each request and then performed the same GET operation 15 times and recorded how long it took each time.</p>
<p>We performed this test twice...</p>
<p>1. Once running on the Microsoft supplied device emulator</p>
<p>2. Once running on our Tahoe II hardware.</p>
<p>... and the results were interesting.</p>
<p><a href="http://www.dotnetsolutions.co.uk/blog/Media/WindowsLiveWriter/SocketTimingProblems_C68E/image_2.png"><img width="421" height="308" style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px" title="image" border="0" alt="image" src="http://www.dotnetsolutions.co.uk/blog/Media/WindowsLiveWriter/SocketTimingProblems_C68E/image_thumb.png"></a> </p>
<p>Running the test against the emulator (highlighted on the graph by the blue line) gave us consistent sub 200ms response times 100% of the time. Running on the Tahoe II hardware (the red line on the graph) gave us very erratic response times. Half of the requests returned in under 1 second and the other half took as long as 8 seconds, not a good time at all!</p>
<p>We then ran the same test on a GHI Embedded Development Master System in an attempt to rule out the hardware manufacturer as the cause of the problems and sure enough this device provided just as inconsistent results.</p>
<p><b>The Solution:</b></p>
<p>Migrate to .Net 4.0... Now this sounds like a fairly dramatic solution but if the success of your project is defined by delivering good, constant response times when communicating over HTTP or indeed any other protocol over TCP then you will need to use the latest Micro Framework offering from Microsoft.</p>
<p>We approached Microsoft about this issue, presenting our evidence and reproducible steps for them to see with their own eyes. They were quick to acknowledge that we had indeed discovered a bug in their TCP stack and took the appropriate steps to fix this in version 4 of the .Net Micro Framework before releasing it. </p>
<p>Whilst no fix has been provided for version 3 of the Micro Framework we were able to mitigate against these problems because we did not require sub 1 second response times (although it would have been nice).</p>
<p><b>As a side note...</b></p>
<p>The other issue that this highlighted was the importance of having real hardware to develop against as early as possible in your .Net Micro Framework projects. As our testing shows – had we spent the majority of our project working on software emulated devices we would have never discovered this issue. </p>
<p><a href="http://www.dotnetsolutions.co.uk/blog/archive/2010/08/18/unit-testing-the-net-micro-framework" target="_blank">Unit testing</a> and a strong emphasis on code quality can only help you so much in your project. There are some things that you will only ever notice with real hardware. I suspect the same is true of all projects that have a hardware element – be it other embedded development platforms or indeed mobile development.</p>
<p>Author: Gavin Osborn <br>
<a href="http://twitter.com/gavinosborn" target="_blank"><img alt="" border="0" src="http://a4.twimg.com/images/favicon.gif">@gavinosborn</a> <br>
<br>
<a href="http://twitter.com/share?url=http://www.dotnetsolutions.co.uk/blog/archive/2010/09/06/Socket-Timing-Problem/&amp;via=dotnetsolutions&amp;related=gavinosborn&amp;text=Socket Timing Problem" target="_blank"><img alt="" border="0" src="http://a4.twimg.com/images/favicon.gif">Tweet</a></p>

</div>]]></description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">DOTNETSOL\Marcus</dc:creator><pubDate>Mon, 06 Sep 2010 14:09:00 GMT</pubDate><category domain="http://www.dotnetsolutions.co.uk/blog/archive/tags/Micro Framework/">Micro Framework</category></item><item><title>Linger error</title><link>http://www.dotnetsolutions.co.uk/blog/archive/2010/09/02/linger-error/</link><guid isPermaLink="False">/blog/archive/2010/09/02/linger-error/</guid><description><![CDATA[<div class="ExternalClass7484065DFA2247FDA119EA411D5CED15">
<p>One of the more significant challenges that we have faced during our last project presented itself to us about halfway through the project timeline. Our .Net Micro Framework application regularly sends messages to remote endpoints out on the internet over HTTPS/TCP. In isolation a single HTTPS request using the .Net Micro Framework was a pain free operation (even if there is no HTTPS stack out of the box). However, the problem was that after an indeterminate period of time our application would stop sending HTTP requests and would die a horrible death.</p>
<p>To confound matters further no exception were being raised and so we were not even able to catch the exception to a) gather more information or b) gracefully handle the error. Instead the board would just lock up and stop working, as the .Net Micro Framework runtime had crashed. </p>
<p>Given that we were not receiving an exception of any kind initial testing focused on the hardware that we were running on. We tested our software on both the <a href="http://www.ghielectronics.com/product/108">GHI Master Development System</a> and the <a href="http://www.devicesolutions.net/Products/TahoeII.aspx">Tahoe II board from Device Solutions Ltd</a> yet both products exhibited the same problems.</p>
<p>Focus shifted back to software, but given that no exceptions were throw and connecting to the device using the MF Deploy tool yielded no additional insight we could not ascertain the cause of the problem. Having scoured the code-base for any clues we decided to approach Microsoft with our rather odd problem. </p>
<p>After discussing the many intricacies of our application with the .Net Micro Framework team they provided us with an early build of the MF Deploy tool that was to be released with version 4 of the Framework. As soon as we started using this new version of MF deploy we started making progress.</p>
<p>The first thing that happened is we started to get an exception and stack trace information in the MF Deploy trace information. Now we had something to work from!</p>
<p>#### Exception System.Net.Sockets.SocketException - E_FAIL (1) #### <br>
#### Microsoft.SPOT.Net.SocketNative::socket [IP: 0000] #### <br>
#### System.Net.Sockets.Socket::.ctor [IP: 001f] #### <br>
#### SocketException ErrorCode = 10024</p>
<p>A brief search using <a href="http://www.red-gate.com/products/reflector/">Reflector</a> quickly led us to a brief description of the problem:</p>
<p><a href="http://www.dotnetsolutions.co.uk/blog/Media/WindowsLiveWriter/Lingererror_9BE2/image_2.png"><img width="438" height="349" style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px" title="image" border="0" alt="image" src="http://www.dotnetsolutions.co.uk/blog/Media/WindowsLiveWriter/Lingererror_9BE2/image_thumb.png"></a> </p>
<p>OK, so apparently we have opened too many sockets. Unfortunately; as is so often the case; this only succeeded in posing more questions than it answered.</p>
<p>Our HTTPS/TCP code opened and closed a socket on every request. Our Socket object was also wrapped in a using statement which meant that it would be disposed of after every call.</p>
<div class="csharpcode">
<pre class="alt">IPAddress address = GetHostAddress(uri);</pre>
<pre>IPEndPoint endpoint = <span class="kwrd">new</span> IPEndPoint(address, 80);</pre>
<pre class="alt"><span class="kwrd">using</span> (Socket socket = <span class="kwrd">new</span> Socket(</pre>
<pre>    AddressFamily.InterNetwork,</pre>
<pre class="alt">       SocketType.Stream, ProtocolType.Tcp))</pre>
<pre>{</pre>
<pre class="alt">    <span class="rem">//open the socket</span></pre>
<pre>    socket.Connect(endpoint);</pre>
<pre class="alt"> </pre>
<pre>    <span class="rem">//HTTP writing code removed </span></pre>
<pre class="alt">    <span class="rem">//to keep sample terse.</span></pre>
<pre>    <span class="rem">//close the socket</span></pre>
<pre class="alt">    socket.Close();</pre>
<pre><span class="rem">//dispose the socket</span></pre>
<pre class="alt">}</pre>
</div>
<p>So then why do we have too many sockets open? Another look at Reflector only served to strengthen our resolve that we had done everything correctly. The Dispose method did appear to clean up any of the native resources used by the Socket object:</p>
<p><a href="http://www.dotnetsolutions.co.uk/blog/Media/WindowsLiveWriter/Lingererror_9BE2/image_4.png"><img width="457" height="414" style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px" title="image" border="0" alt="image" src="http://www.dotnetsolutions.co.uk/blog/Media/WindowsLiveWriter/Lingererror_9BE2/image_thumb_1.png"></a> </p>
<p>Confused once more we approached Microsoft for an answer to our problems.</p>
<p>It was then that they informed us that by default when you close a Socket in the .Net Micro Framework it does not actually release the Socket for a further 2 minutes! This value is an option that you can set yourself with the following line of code:</p>
<div class="csharpcode">
<pre class="alt">socket.SetSocketOption(SocketOptionLevel.Tcp</pre>
<pre>                               , SocketOptionName.Linger</pre>
<pre class="alt">                               , <span class="kwrd">new</span> <span class="kwrd">byte</span>[] { 0, 0, 0, 0 });</pre>
</div>
<p> </p>
<p>So what is SocketOptionName.Linger? Assuming that it is the same as its <a href="http://msdn.microsoft.com/en-us/library/system.net.sockets.socketoptionname.aspx">big brother equivalent in the .Net Framework</a> it is an option that is used to tell the socket to wait before closing so that any unsent data can be sent.</p>
<p>It should only be necessary to set the Linger time to 0 if you are expecting to open another Socket to the same address and port. If you are to set the Linger time to 0 then it is also recommended that you also set the NoDelay option to true so that any messages are sent immediately.</p>
<div class="csharpcode">
<pre class="alt">socket.SetSocketOption(SocketOptionLevel.Tcp</pre>
<pre>                      , SocketOptionName.NoDelay</pre>
<pre class="alt">                      , <span class="kwrd">true</span>);</pre>
</div>
<p>Complete example:
<style>
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode, .ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode pre
{font-size:small;color:black;font-family:consolas, &quot;Courier New&quot;, courier, monospace;background-color:#ffffff;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode pre
{margin:0em;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .rem
{color:#008000;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .kwrd
{color:#0000ff;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .str
{color:#006080;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .op
{color:#0000c0;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .preproc
{color:#cc6633;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .asp
{background-color:#ffff00;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .html
{color:#800000;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .attr
{color:#ff0000;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .alt
{background-color:#f4f4f4;width:100%;margin:0em;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .lnum
{color:#606060;}
</style>
</p>
<div class="csharpcode">
<pre class="alt">IPAddress address = GetHostAddress(uri);</pre>
<pre>IPEndPoint endpoint = <span class="kwrd">new</span> IPEndPoint(address, 80);</pre>
<pre class="alt"><span class="kwrd">using</span> (Socket socket = <span class="kwrd">new</span> Socket(</pre>
<pre>        AddressFamily.InterNetwork</pre>
<pre class="alt">       ,SocketType.Stream</pre>
<pre>       ,ProtocolType.Tcp))</pre>
<pre class="alt">{</pre>
<pre>    socket.SetSocketOption(SocketOptionLevel.Tcp</pre>
<pre class="alt">        , SocketOptionName.Linger</pre>
<pre>        , <span class="kwrd">new</span> <span class="kwrd">byte</span>[] { 0, 0, 0, 0 });</pre>
<pre class="alt">    socket.SetSocketOption(SocketOptionLevel.Tcp</pre>
<pre>        , SocketOptionName.NoDelay, <span class="kwrd">true</span>);</pre>
<pre class="alt">        </pre>
<pre>    <span class="rem">//open the socket</span></pre>
<pre class="alt">    socket.Connect(endpoint);</pre>
<pre> </pre>
<pre class="alt">    <span class="rem">//HTTP writing code removed </span></pre>
<pre>    <span class="rem">//to keep sample terse.</span></pre>
<pre class="alt"> </pre>
<pre>    <span class="rem">//close the socket</span></pre>
<pre class="alt">    socket.Close();</pre>
<pre><span class="rem">//dispose the socket</span></pre>
<pre class="alt">}</pre>
</div>
<style>
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode, .ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode pre
{font-size:small;color:black;font-family:consolas, &quot;Courier New&quot;, courier, monospace;background-color:#ffffff;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode pre
{margin:0em;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .rem
{color:#008000;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .kwrd
{color:#0000ff;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .str
{color:#006080;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .op
{color:#0000c0;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .preproc
{color:#cc6633;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .asp
{background-color:#ffff00;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .html
{color:#800000;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .attr
{color:#ff0000;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .alt
{background-color:#f4f4f4;width:100%;margin:0em;}
.ExternalClass93D8BC98AFF248C7A233EF701CCD8BEF .csharpcode .lnum
{color:#606060;}
</style>
<p>While we expecienced this problem using version 3 of the .Net Micro Framework, I am not aware whether the default behaviour has been changed in version 4.</p>
<p>This was the first (and simplest) of several intricacies in the .Net Micro Framework that we encountered during the course of this project. More in another blog post soon.</p>
<p>Author: Gavin Osborn <br>
<a href="http://twitter.com/gavinosborn" target="_blank"><img alt="" border="0" src="http://a4.twimg.com/images/favicon.gif">@gavinosborn</a> <br>
<br>
<a href="http://twitter.com/share?url=http://www.dotnetsolutions.co.uk/blog/archive/2010/09/02/Linger-error/&amp;via=dotnetsolutions&amp;related=gavinosborn&amp;text=Linger error" target="_blank"><img alt="" border="0" src="http://a4.twimg.com/images/favicon.gif">Tweet</a></p>

</div>]]></description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">DOTNETSOL\Marcus</dc:creator><pubDate>Thu, 02 Sep 2010 11:07:00 GMT</pubDate><category domain="http://www.dotnetsolutions.co.uk/blog/archive/tags/Micro Framework/">Micro Framework</category></item></channel></rss>
