Main Site Documentation

[SOLVED] panda II & ethernet shield



I’m trying to test arduino ethernet shield with panda II card. I just try the sample code given in the tutorial.

using System;
using System.Text;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.Sockets;
using GHIElectronics.NETMF.Net.NetworkInformation;

using Socket = GHIElectronics.NETMF.Net.Sockets.Socket;

/// <summary>
/// This is a simple web server. Given a request, it returns an HTML document. 
/// The same document is returned for all requests and no parsing of
/// the request is done.
/// </summary>
public static class MySocketServer
    public static void Main()
        const Int32 c_port = 80;

        byte[] ip = { 172, 17, 210, 200 };
        byte[] subnet = { 255, 255, 0, 0 };
        byte[] gateway = { 172, 17, 0, 1 };
        byte[] mac = { 0x00, 0x26, 0x1C, 0x7B, 0x29,0xE8 };

                            (Cpu.Pin)FEZ_Pin.Digital.Di9, true);

            NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
            NetworkInterface.EnableStaticDns(new byte[] { 172, 17, 0, 1 });

            Socket server = new Socket(AddressFamily.InterNetwork,
            SocketType.Stream, ProtocolType.Tcp);

//            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, c_port);
            IPAddress hostIPAddress = IPAddress.Parse("");
            IPEndPoint localEndPoint = new IPEndPoint(hostIPAddress, c_port);


            while (true)
                // Wait for a client to connect.
         [b]       Socket clientSocket = server.Accept();// problem here[/b]
                // Process the client request. true means asynchronous.
                new ProcessClientRequest(clientSocket, true);
        catch (Exception e)
    /// <summary>
    /// Processes a client request.
    /// </summary>
    internal sealed class ProcessClientRequest
        private Socket m_clientSocket;
        /// <summary>
        /// The constructor calls another method to handle the request, 
        /// but can optionally do so in a new thread.
        /// </summary>
        /// <param name="clientSocket"></param>
        /// <param name="asynchronously"></param>
        public ProcessClientRequest(Socket clientSocket,
                                    Boolean asynchronously)
            m_clientSocket = clientSocket;
            if (asynchronously)
                // Spawn a new thread to handle the request.
                new Thread(ProcessRequest).Start();
            else ProcessRequest();
        /// <summary>
        /// Processes the request.
        /// </summary>
        private void ProcessRequest()
            const Int32 c_microsecondsPerSecond = 1000000;
            // 'using' ensures that the client's socket gets closed.
            using (m_clientSocket)
                // Wait for the client request to start to arrive.
                Byte[] buffer = new Byte[1024];
                if (m_clientSocket.Poll(5 * c_microsecondsPerSecond,
                    // If 0 bytes in buffer, 
                    // then the connection has been closed,
                    // reset, or terminated.
                    if (m_clientSocket.Available == 0)
                    // Read the first chunk of the request 
                    // (we don't actually do anything with it).
                    Int32 bytesRead = m_clientSocket.Receive(buffer,
                    m_clientSocket.Available, SocketFlags.None);

                    // Return a static HTML document to the client.
                    String s =
                    "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n\r\n<html><head><title>.NET Micro Framework Web Server on USBizi Chipset </title></head>"
                    + "<body><bold><a href=\"\">Learn more about the .NET Micro Framework with FEZ by clicking here</a></bold></body></html>";
                    byte[] buf = Encoding.UTF8.GetBytes(s);
                    int offset = 0;
                    int ret = 0;
                    int len = buf.Length;
                    while (len > 0)
                        ret = m_clientSocket.Send(buf, offset, len,
                        len -= ret;
                        offset += ret;

But the call to function Accept fail. I have inserted a try catch to intercept exception. So the message is:
#### Exception System.Exception - 0x00000000 (1) ####
#### Message: Fail[invalid ip,port]

I’ve replaced IPAddress.Any by the IP address of the card but without result.

What can I do?

Thank you

Joe: I fixed the MAC address


You have commented out the following line of code.

IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, c_port);


What happens if you use the original code in the sample?


What shield exactly are you using ? If it is the Arduino Ethershield (v5) with the micro SD card reader embedded, you will most likely need to modify a little bit the shield for the SPI wires to be redirected from the small connector “under the board” to the SPI pins on the panda II (DI11, DI12, DI13), plus the CS and reset lines (DI9 and DI10). This is easy to do but requires soldering a few wires… :slight_smile:

Furthermore, Mike is right, if you are using a web server you should not listen to your own IP address ! :wink:


Here is the WiKi page that show you how to modify your shield:


Thank’s Sam, Nicolas and Mike. I’ve add the three wires and it’s clear now.

[quote]Furthermore, Mike is right, if you are using a web server you should not listen to your own IP address !
[/quote]does the panda have other IP address? It’s clear too if I bind with

The IP address of the computer is


[quote] It’s clear too if I bind with


I did not know you had not wired the shield correctly.

It is not necessary to bind to you interface address. I guess it works, but it is good practice not to hardcode any address that is not necessary.


Only one IP address is possible (unlike a PC for an example). So as far as I understood “binding” does not have exactly the same meaning here. IPAddress.Any worked for all my tests !


thank for these advices

Very good forum !


I recently found out a design bug for this particular shield, on the power side, and I modified the wiki accordingly to allow people to fix it !


It’s what I’ve made