mIP - 100% C# Managed TCP/IP Stack for the .NET Micro Framework

Sign in to queue


Today's Hardware Friday post isn't about a price of hardware (I know, imagine that!). Instead it's a project that gives you the tools to talk to, and add advanced networking features, your hardware projects via TCP/IP using C#.

mIP - A C# Managed TCP/IP Stack for .NET Micro Framework

mIP (short for Managed Internet Protocol) is a 100% managed TCP/IP stack for .NET MicroFramework

The purpose of mIP is to empower the C# developer to debug and add advanced networking features without having to change the firmware or learn C++. Since this is targeted to embedded devices, this library strives to use a minimal memory footprint. Also, the classes and methods MUST be simple and obvious to use and the critical public methods will be commented properly to allow for proper intellisense. Also, initially, the focus is to enable web server functionality


Primary Goals:

  • Durability -- keep running despite exceptions
  • Never block -- No method should ever block and the code should be written to make this impossible
  • Features that make usage and discovery simple for the end-user
    • Sensible default values such as DHCP on by default
    • Support for Local Naming such as mDNS and even NetBIOS over TCP
  • Small -- embedded devices have very little memory
  • Simple code -- code should be easy and simple to foster contributions
  • Minimize validation -- Validation is great if we have lots of memory, but beyond validating checksums and packet sizes, there won't be much. For instance, since there are no generics, ArrayList and Hashtable are used and type checking everything is not necessary when only private methods populate these collections...

Current Features:

  • Simplified handlers for HTTP
    • Request and Response objects modeled after desktop .NET Framework
  • ARP
  • DHCP (Dynamic IP, DNS, gateway address discovery, & propagates name to router)
    • Tested with 2-Wire 3800HGV
    • Tested with D-Link EBR-2310
    • Tested with Netgear WGR-614
  • ICMP (Responds to Ping requests)
  • TCP (Receives 1 packet, sends many)
  • UDP
  • Multicast DNS (mDNS) for local Naming
  • Link-Local Multicast Name Resolution for Local Naming
  • NetBIOS over TCP (to support WinXP)
  • Driver for ENC28J60 Ethernet Controller (License compatible for commercial use)
  • Supports Cable connect/disconnect events and renegotiates IP automatically (if DHCP is enabled)
  • Withstands flood of packets without crash (such as that caused by holding the F5 key on browser)

The project includes some documentation to get you started as well.



And of course you get the source for both the example services, web server, DNS, UDP,  and the service itself too.


Note: As you can see above the current change set, c32d8665ec50 is missing the debug.cs file so it won't compile as is. But it's simple enough to create your own and stub out the method the method...


Six lines (well seven) for your own .Net Micro Framework web server?

namespace NetworkingExample
    public class WebServerProgram
        public static void Main()
            #region Static IP example
            //Networking.Adapter.IPAddress = new byte[] { 0xc0, 0xa8, 0x01, 0x5f };  //
            //Networking.Adapter.DnsServer = new byte[] { 0xc0, 0xa8, 0x01, 0xfe };  //
            //Networking.Adapter.Gateway = new byte[] { 0xc0, 0xa8, 0x01, 0xfe };  //
            //Networking.Adapter.DhcpDisabled = true;

            // http://forums.netduino.com/index.php?/topic/322-experimental-drivers-for-wiznet-based-ethernet-shields/page__view__findpost__p__3170
            // 5C-86-4A-00-00-DD   This is a test MAC address from Secret Labs
            // Note: This MAC address should be Unique, but it should work fine on a local network (as long as there is only one instance running with this MAC)
            Networking.Adapter.Start(new byte[] { 0x5c, 0x86, 0x4a, 0x00, 0x00, 0xdd }, "mip", InterfaceProfile.Cerb40_ENC28J60);
            Networking.Adapter.OnHttpReceivedPacketEvent += new Adapter.HttpPacketReceivedEventHandler(Adapter_OnHttpReceivedPacketEvent);
            Networking.Adapter.ListenToPort(80);  // Listen on Port 80, the default web server port
            // Loop to keep program alive
            while (true) Thread.Sleep(100);

        static void Adapter_OnHttpReceivedPacketEvent(HttpRequest request)
             //byte[] webPage = Encoding.UTF8.GetBytes("<html><head><meta http-equiv=\"refresh\" content=\"5\"></head><body><font face=\"verdana\"><h1>mip - A Managed TCP/IP Stack</h1><p>for .NET MicroFramework</p><p>This is just the beginning :)</p><p><a href=\"http://mip.codeplex.com\">Visit us at Codeplex!</a></p></font></body></html>");
            byte[] webPage = Encoding.UTF8.GetBytes("<html><body><font face=\"verdana\"><h1>mip - A Managed TCP/IP Stack</h1><p>for .NET MicroFramework</p><p>This is just the beginning :)</p><p><a href=\"http://mip.codeplex.com\">Visit us at Codeplex!</a></p></font></body></html>");
            var s = new System.IO.MemoryStream(webPage);  // substitute a FileStream here when reading from MicroSD
            request.SendResponse(new HttpResponse(s));

If you've ever wondered what a TCP/IP stack would look like, or need one for your next .Net Micro Framework project, mIP is waiting for your connection...

The Discussion

Add Your 2 Cents