<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.microsoft.co.il/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Ido Flatow&amp;#39;s Blog&lt;h3&gt;Veni Vidi Scripsi&lt;/h3&gt; : UDP</title><link>http://blogs.microsoft.co.il/blogs/idof/archive/tags/UDP/default.aspx</link><description>Tags: UDP</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>What’s new in WCF 4.5? UDP transport support</title><link>http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/15/what-s-new-in-wcf-4-5-udp-transport-support.aspx</link><pubDate>Thu, 16 Feb 2012 03:50:00 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1014306</guid><dc:creator>Ido Flatow</dc:creator><slash:comments>12</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/idof/rsscomments.aspx?PostID=1014306</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/15/what-s-new-in-wcf-4-5-udp-transport-support.aspx#comments</comments><description>&lt;p&gt;This is the tenth post in the WCF 4.5 series. I’ve started this series of posts 4 months ago when &lt;a href="http://msdn.microsoft.com/en-us/netframework/hh403373"&gt;.NET 4.5 developer preview&lt;/a&gt; was announced; The Beta/RC/RTM version is still to come, but hopefully it will be available soon, and you will be able to use the new WCF 4.5 features in your projects.&lt;/p&gt;
&lt;p&gt;Until now, I’ve shown new features in configuration easiness and hosting improvements. In this post and the next one I will cover new transport features, starting with the support for the UDP transport.&lt;/p&gt;
&lt;p&gt;Previous posts:&lt;/p&gt;
&lt;p&gt;1. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/16/what-s-new-in-wcf-4-5-let-s-start-with-wcf-configuration.aspx"&gt;What’s new in WCF 4.5? let’s start with WCF configuration&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;2. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/17/what-s-new-in-wcf-4-5-a-single-wsdl-file.aspx"&gt;What’s new in WCF 4.5? a single WSDL file&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;3. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/19/what-s-new-in-wcf-4-5-configuration-tooltips-and-intellisense-in-config-files.aspx"&gt;What’s new in WCF 4.5? Configuration tooltips and intellisense in config files&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;4. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/25/what-s-new-in-wcf-4-5-configuration-validations.aspx"&gt;What’s new in WCF 4.5? Configuration validations&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;5. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/25/what-s-new-in-wcf-4-5-multiple-authentication-support-on-a-single-endpoint-in-iis.aspx"&gt;What’s new in WCF 4.5? Multiple authentication support on a single endpoint in IIS&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;6. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/05/what-s-new-in-wcf-4-5-automatic-https-endpoint-for-iis.aspx"&gt;What’s new in WCF 4.5? Automatic HTTPS endpoint for IIS&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;7. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/10/what-s-new-in-wcf-4-5-basichttpsbinding.aspx"&gt;What’s new in WCF 4.5? BasicHttpsBinding&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;8. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/what-s-new-in-wcf-4-5-changed-default-for-asp-net-compatibility-mode.aspx"&gt;What’s new in WCF 4.5? Changed default for ASP.NET compatibility mode&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;9. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/17/what-s-new-in-wcf-4-5-improved-streaming-in-iis-hosting.aspx"&gt;What’s new in WCF 4.5? Improved streaming in IIS hosting&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I’ve been teaching WCF for several years now, and almost every time I explain to people about the different types of bindings and supported transports someone asks me if there is a built-in support for a UDP transport. Until now my answer was “It isn’t supported out-of-the-box, but there is a &lt;a href="http://msdn.microsoft.com/en-us/library/ms751494.aspx"&gt;UDP transport sample&lt;/a&gt; in the &lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;amp;id=21459"&gt;WCF/WF samples&lt;/a&gt;”. From now on my new answer is “In WCF 4/3.5 there is a sample implementation, but it is now out-of-the-box in WCF 4.5”.&lt;/p&gt;
&lt;p&gt;You can get some basic info about the binding in the &lt;a href="http://msdn.microsoft.com/en-us/library/ms730879(v=vs.110).aspx"&gt;System-Provided Bindings&lt;/a&gt; page on MSDN (make sure you look at the 4.5 version), unfortunately there is no documentation on the UdpBinding type yet, but hopefully MS will create it by the time WCF 4.5 is released.&lt;/p&gt;
&lt;p&gt;Declaring an endpoint that uses UDP is quite simple:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;soap.udp://localhost:8080/&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;udpBinding&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;UdpHost.IService&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Some facts about the new UDP binding:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The address scheme for this binding is &lt;strong&gt;soap.udp://&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;The binding is supported only&amp;nbsp;by .NET (since it does uses text encoding for the SOAP messages, it can be considered interoperable, although currently no other SOAP-based services technology support UDP)&lt;/li&gt;
&lt;li&gt;Security is not supported (neither transport or message) &lt;/li&gt;
&lt;li&gt;Sessions, transactions, streaming, and duplex are not supported (I was hoping for a duplex UDP using one-way messages) &lt;/li&gt;
&lt;li&gt;Supported encoding is text &lt;/li&gt;
&lt;li&gt;The binding can be used in code by adding a reference to the System.ServiceModel.Channels assembly &lt;/li&gt;
&lt;li&gt;The binding is not supported in IIS/WAS, since there is still no UDP shared listener for WAS&lt;/li&gt;
&lt;li&gt;In the case of One-Way messages, this is a true one-way unidirectional call - the client won’t throw an exception if the service is unavailable &lt;/li&gt;
&lt;li&gt;If you specify a &lt;a href="http://en.wikipedia.org/wiki/Multicast_address"&gt;multicast address&lt;/a&gt; in the endpoint, such as 224.0.0.1 or 239.255.255.255 (the later is used by UDP discovery endpoints), you can create multiple listeners on the same address+protocol even from different machines – one client can send a single message that will be received by multiple listeners – this can be a great way to synchronize server state, do pub-sub (notification) calls etc...&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Using a multicast listening address is also quite simple:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;soap.udp://239.255.255.255:8083/&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;udpBinding&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;UdpHost.IService&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;As for performance, I’ve create a simple client which sends 5000 messages using request-response and one-way (simple and multicast), with HTTP (basicHttp), TCP, and UDP bindings. For the purpose of the test I’ve removed all security settings from the NetTcp binding. The result is shown below:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations one way using UDP &lt;br /&gt;One-way using UDP took 0 seconds, average is 0.1792ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations one way using HTTP &lt;br /&gt;One-way using HTTP took 6 seconds, average is 1.3ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations one way using TCP &lt;br /&gt;One-way using TCP took 2 seconds, average is 0.5876ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations one way using UDP Multicast &lt;br /&gt;One-way using UDP Multicast took 3 seconds, average is 0.736ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations of request-response using UDP &lt;br /&gt;Request-response using UDP took 7 seconds, average is 1.4738ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations of request-response using HTTP &lt;br /&gt;Request-response using HTTP took 8 seconds, average is 1.7784ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations of request-response using TCP &lt;br /&gt;Request-response using TCP took 4 seconds, average is 0.9518ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Conclusions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;One-way messages are fast when using UDP – about 7 times faster than HTTP, and 3 times faster than TCP. I assume this is because when using UDP we don’t need to wait for the TCP &lt;a href="http://en.wikipedia.org/wiki/Acknowledgement_(data_networks)"&gt;ACK&lt;/a&gt; (also used in HTTP).&lt;/li&gt;
&lt;li&gt;One-way multicast messages in UDP are slower than direct messages – about 4 times slower&lt;/li&gt;
&lt;li&gt;Request-response message in UDP are slower than TCP, but faster than HTTP. I assume the reason for being slower than TCP is that UDP uses two channels to create request-response whereas TCP requires only one channel.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Trying to run the same sample when the server has not been started produces the following results:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations one way using UDP &lt;br /&gt;One-way using UDP took 0 seconds, average is 0.1216ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations one way using HTTP &lt;br /&gt;One-way using HTTP failed&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations one way using TCP &lt;br /&gt;One-way using TCP failed&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations one way using UDP Multicast &lt;br /&gt;One-way using UDP Multicast took 1 seconds, average is 0.376ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations of request-response using UDP &lt;br /&gt;Request-response using UDP failed&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations of request-response using HTTP &lt;br /&gt;Request-response using HTTP failed&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations of request-response using TCP &lt;br /&gt;Request-response using TCP failed&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;As you can see, UDP one-way messages are unidirectional!!!&lt;/p&gt;
&lt;p&gt;The sample code is available on my &lt;a href="https://skydrive.live.com/redir.aspx?cid=5ef5be1ab30a6056&amp;amp;resid=5EF5BE1AB30A6056!467&amp;amp;parid=5EF5BE1AB30A6056!129"&gt;SkyDrive&lt;/a&gt;.&lt;/p&gt;
&lt;div style="PADDING-BOTTOM:0px;MARGIN:0px;PADDING-LEFT:0px;PADDING-RIGHT:0px;PADDING-TOP:0px;" class="wlWriterHeaderFooter"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/15/what-s-new-in-wcf-4-5-udp-transport-support.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/15/what-s-new-in-wcf-4-5-udp-transport-support.aspx&amp;amp;bgcolor=6600FF" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/Submit?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/15/what-s-new-in-wcf-4-5-udp-transport-support.aspx"&gt;&lt;img style="BORDER-BOTTOM:0px;BORDER-LEFT:0px;BORDER-TOP:0px;BORDER-RIGHT:0px;" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/15/what-s-new-in-wcf-4-5-udp-transport-support.aspx" /&gt;&lt;/a&gt; 
&lt;div class="addthis_toolbox addthis_default_style "&gt;&lt;a class="addthis_button_preferred_1"&gt;&lt;/a&gt;&lt;a class="addthis_button_preferred_2"&gt;&lt;/a&gt;&lt;a class="addthis_button_preferred_3"&gt;&lt;/a&gt;&lt;a class="addthis_button_preferred_4"&gt;&lt;/a&gt;&lt;a class="addthis_button_compact"&gt;&lt;/a&gt;&lt;a class="addthis_counter addthis_bubble_style"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4f27f7864794397c"&gt;&lt;/script&gt;
&lt;a style="DISPLAY:none;" href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=2199681" rel="tag"&gt;CodeProject&lt;/a&gt; &lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1014306" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/What_2700_s+new/default.aspx">What's new</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF+4.5/default.aspx">WCF 4.5</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/UDP/default.aspx">UDP</category></item></channel></rss>