Why can I not see two EMX IP addresses in my network?

I have 2 Cobra boards, and the 2 Cobra board are connected to a switch. The both EMXs are written the same codes as follow:


using System;
using System.Net;
using System.Text;
using System.Threading;
using System.Net.Sockets;

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

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;

namespace DCHP_test
{
    public class Program
    {
        public static void Main()
        {
            // First, make sure we actually have a network interface to work with!
            if (Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces().Length < 1)
            {
                Debug.Print("No Active network interfaces. Bombing out.");
                Thread.CurrentThread.Abort();
            }

            // OK, retrieve the network interface
            Microsoft.SPOT.Net.NetworkInformation.NetworkInterface NI = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0];

            // If DHCP is not enabled, then enable it and get an IP address, else renew the lease. Most iof us have a DHCP server
            // on a network, even at home (in the form of an internet modem or wifi router). If you want to use a static IP
            // then comment out the following code in the "DHCP" region and uncomment the code in the "fixed IP" region.
          
            if (NI.IsDhcpEnabled == false)
            {
                Debug.Print("Enabling DHCP.");
                NI.EnableDhcp();
                Debug.Print("DCHP - IP Address = " + NI.IPAddress + " ... Net Mask = " + NI.SubnetMask + " ... Gateway = " + NI.GatewayAddress);
            }
            else
            {
                Debug.Print("Renewing DHCP lease.");
                NI.RenewDhcpLease();
                Debug.Print("DCHP - IP Address = " + NI.IPAddress + " ... Net Mask = " + NI.SubnetMask + " ... Gateway = " + NI.GatewayAddress);
            }


            // Create the socket            
            Socket listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            // Bind the listening socket to the port
            IPAddress hostIP = IPAddress.Parse(NI.IPAddress);
            IPEndPoint ep = new IPEndPoint(hostIP, 80);
            listenSocket.Bind(ep);


            // Start listening
            listenSocket.Listen(1);

            // Main thread loop
            while (true)
            {
                try
                {
                    Debug.Print("listening...");
                    Socket newSock = listenSocket.Accept();
                    Debug.Print("Accepted a connection from " + newSock.RemoteEndPoint.ToString());
                    byte[] messageBytes = Encoding.UTF8.GetBytes("Hello, browser! I think the time is " + DateTime.Now.ToString());
                    newSock.Send(messageBytes);
                    newSock.Close();
                }
                catch (Exception e)
                {
                    Debug.Print(e.Message);
                }
            }
        }

    }
}

I have installed a DHCP Server in my Computer, but I can olny see a Cobra board IP adresse with tool software “Wireless Network Watcher” in my network, why not 2 IP addresses?

I thought, 2 IP addresses would be showed in “Wireless Network Watcher”. How can I see 2 IP addresses?

Well for one, “wireless network watcher” may not show you what you expect? Why don’t you grab Network Monitor and look at the traffic, and look at what MAC addresses as well as IP addresses go over the wire. Or what about looking at the DHCP server to see what addresses it’s given out?

By any chance have you duplicated the MAC on the two devices? If so, that would be what is going on - they have to be “unique” across the network otherwise most tools think it’s traffic from the same device

@ Brett -

you are right, they have to be “unique” across the network.
After changing the MAC of one Cobra I can see 2 Cobras on “Wireless Network Watcher”.
thanks a lot!!

@ Brett -

one more question, how can I test the code example?

After debuging the programm stopt at “listening”, how can I send somthing to Cobra, so that Cobra can receive someting?

There are examples of sockets programming provided with the Microsoft SDK. They are located on your hard disk, in the folder"C:\Users\yourusername\Documents\Microsoft .NET Micro Framework4.2\Samples". The two examples are SocketServer and SocketClient. They will give the answers you seek.