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?