InfiniTec - Henning Krauses Blog

Don't adjust your mind - it's reality that is malfunctioning

Implement an UDP multicast client/server communication

Affected products

  • .NET Framework 1.0
  • .NET Framework 1.1


This article explains, how to implement a multicast client/server communication using the UDP protocol.


One feature of the UDP Protocoll is the support for multicast messages. This are messages, that are sent from one host to multiple clients. Additionally, the sending host does not need to know the destination of the packets. Instead, it sends the packet to a special IP address (in the range from to This address is called a multicast group.
The client, on the other side, registers itself to this address on the next hop on the route to the source host. This process is called "joining a multicast group". This next hop is either a router or the destination host. If it is a router, it will propagate this registration forward to the next router, until the destination host is reached.
The MSDN documentation contains an article that covers this topic, but it has two drawbacks:
The client component described in that article does only allow one client on one machine, and
the code doesn't work.


For the client component, use the following code:
multicastListener = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,ProtocolType.Udp);
multicastListener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
multicastListener.Bind(new IPEndPoint(IPAddress.Any, 65000));
multicastListener.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(new IPAddress(""), IPAddress.Any));
This will create a socket that is bound to port 65000. The second line sets the socket in a non-exclusive state, thus allowing other process to bind to the same port. Finally, the fourth line will cause the socket to join the specified multicast group on all network interfaces.
The following code makes up the server part. It will create a socket, that will open the multicast group on the address, port 65000.
multicastSender = new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp );
multicastSender.Bind(new IPEndPoint(IPAddress.Any, 0));
multicastSender.Connect(new IPEndPoint(new IPAddress("", 65000)));
To send messages to the multicast group, the following code is used:
buffer = Encoding.UTF8.GetBytes("Hello world!");

More informations

The UDP protocoll is a connectionless, non-reliable protocol. This means, that no connection has to be established before one can send data. Further, it is neither guaranteed that the packets are received by the remote host in the order they were sent, nor that they are received at all.
The addresses and are reserved adresses. The first one is a global group, similar to the broadcast addresses of the IP protocol. The second one is a global adress for routers only.
UDP multicast is described in RFC 1112.
Not all router support the IGMP protocol, which is used for multicast group subscription. Especially over the internet, UDP multicast will most likely fail. It is therefore best suited for intranet applications.

Posted by Henning Krause on Friday, December 31, 2004 1:54 PM, last modified on Friday, December 31, 2004 2:26 PM
Permalink | Post RSSRSS comment feed

Programmatically set the value of META-Tags with ASP.NET and C#

Affected products

  • .NET Framework 1.0
  • .NET Framework 1.1


This article explains, how to set the attributes of a META-Tag in an ASP.NET website.


Since there is no META-Tag server control within the .NET framework, and the META tags are in the <head> section, thus outside of the <form> section, it is a little bit tricky to access these tags.


  1. First, create the desired Tag. In this article, a METAREFESH tag will be created. So open the ASP.NET page and insert the following line into the <head> section:
    <meta id="metaRefresh" runat="Server"/>
  2. Now, open the codebehind file, and add the following variable declaration on the class level:
    protected System.Web.UI.HtmlControls.HtmlControl metaRefresh
  3. Note, that the id in the ASP.NET file and the name of the variable must be identically.
  4. In The Page_Load event, add the following code:
    metaRefresh.Attributes["HTTP-EQUIV"] = "refresh";
    metaRefresh.Attributes["content"] = "3;URL=" + myUrl
  5. This code will cause the browser to do a METAREFRESH after 3 seconds. The user will then be redirected to the url specified in the myUrl variable.

Other informations

If you are using WebUserControls and want to access the META tags from within these controls, you should store the desired values in the session object and put the above code into a PreRender event handler. This handler is called after all controls have been loaded. You can then take the values from the Session object and put tehm into the meta tag.

Posted by Henning Krause on Friday, December 31, 2004 1:50 PM, last modified on Tuesday, July 26, 2011 9:57 PM
Permalink | Post RSSRSS comment feed

HttpWebRequest Class has poor performance

Affected Products

  • .NET Framework 1.0
  • .NET Framework 1.1


The HttpWebRequest class performs poorly when sending requests to a server which contain a body.


The HttpWebRequest class performs poorly when sending requests which contain body data to a server. When monitoring the network traffic the following behaviour is seen:
  • The client sends the header of the request to the server.
  • After 350ms the rest of the request is send to the server.


The HttpWebRequest class waits for a HTTP1.1/100-Continue message before sending the body of the request. Additionally, the class supports the Nagle algorithm, which prevents the sending of many small packets to the same target. Instead, the server waits approximately 200 milliseconds, if there are other packets to be send to the same target. It then combines these requests in one packet.


Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.
A hotfix exists (QFE810814) for version 1.0 of the Framework in the languages english and german. The patch is localized for other languages on request. Since it is a quick fix engineering (QFE), it can only be obtained directly from Microsft Support (PSS).
For the .NET Framework 1.1, no patch is necessary, since the behaviour can be controlled programmatically:
HttpWebrequest webRequest = (HttpWebRequest) Webrequest.Create("http://myserver/myfile");
webRequest.ServicePoint.Expect100Continue = false;
webRequest.ServicePoint.UseNagleAlgorithm = false;

Other Information

Note that you must have installed service pack 2 for the .NET Framework 1.0 before applying the patch.
Additionally, some configuration entries must be made in the machine.config file:
  1. Create a new <settings> section within the <> section with the following content:
    <servicePointManager useNagleAlgorithm="false" />
    <servicePointManager expect100Continue="false" />
  2. In order for the .NET Framework to recognize this new section a settings sectionGroup handler needs to be added to the <configSections> portion of machine.config file:
    <sectionGroup name="" >
    <section name="settings" type="System.Net.Configuration.NetConfigurationHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

Posted by Henning Krause on Thursday, December 30, 2004 6:36 PM, last modified on Thursday, July 14, 2011 10:32 PM
Permalink | Post RSSRSS comment feed