Sometimes, but not every time, when I start the Ethernet system, I get this exception:
Exception System.Net.Sockets.SocketException - CLR_E_FAIL (14)
#### Message:
#### Microsoft.SPOT.Net.SocketNative::poll [IP: 0000] ####
#### System.Net.Sockets.Socket::Poll [IP: 0011] ####
#### System.Net.Sockets.Socket::Accept [IP: 0017] ####
#### SocketServer.TCPServer::ProcessServer [IP: 0041] ####
#### SocketException ErrorCode = 10050
#### SocketException ErrorCode = 10050
A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10050
#### SocketException ErrorCode = 10050
2014/08/30 08:15:34.037 SocketServer.ProcessServer( tcp port = 8005 ): exception: Exception was thrown: System.Net.Sockets.SocketException
I am using MF 4.3. Here is my Ethernet startup code:
/// <summary>
/// Start the Client TCP/IP network software
/// </summary>
/// <returns>true if TCP/IP started ok</returns>
private bool StartClient()
{
bool rc = false;
Debug.Print("Initializing ENC28J60 ethernet system");
NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(eth_NetworkAddressChanged);
NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(eth_CableConnectivityChanged);
//GHI.Premium.System.Util.SetMACAddress(GHI.Premium.System.NetworkInterface.ENC28j60_Ethernet, netData.MacAddress);
eth.PhysicalAddress = netData.MacAddress;
Thread.Sleep(2000);
if (!eth.Opened)
{
Debug.Print("Not opened - open ENC28J60 ethernet system");
eth.Open();
}
if (!eth.CableConnected)
{
Debug.Print("Ethernet cable is not connected, waiting for connection");
CableConnectedEvent.WaitOne();
Thread.Sleep(1000);
}
ni = eth.NetworkInterface;
if ( ni == null )
{
rc = false;
return rc;
}
//report MAC address settings
byte[] PhyAddress = netData.MacAddress;
string sMAC = KioskUtilities.BytesToHexString(PhyAddress, PhyAddress.Length);
Debug.Print("MAC address in flash memory = " + sMAC);
PhyAddress = ni.PhysicalAddress;
sMAC = KioskUtilities.BytesToHexString(PhyAddress, PhyAddress.Length);
Debug.Print("MAC address in Network Interface = " + sMAC);
//set IP, Gateway, DNS IPs
ni.EnableStaticIP(netData.StaticIP, netData.NetMask, netData.GatewayAddress);
ni.EnableStaticDns(new string[] { netData.PrimaryDNS, netData.SecondaryDNS });
if (eth.NetworkIsAvailable)
Debug.Print("EthernetENC28J60 is activated");
else
Debug.Print("EthernetENC28J60 is shut down");
if (eth.Opened)
Debug.Print("EthernetENC28J60 interface is open and assigned to TCP/IP");
else
Debug.Print("EthernetENC28J60 interface is closed");
if (eth.CableConnected)
Debug.Print("EthernetENC28J60 cable is connected");
else
Debug.Print("EthernetENC28J60 cable is not connected");
int waitCount = 60;
bool niSet = false;
while ( (waitCount > 0) && !niSet )
{
Thread.Sleep(1000);
waitCount--;
if ((ni.IPAddress == netData.StaticIP) && (ni.SubnetMask == netData.NetMask))
niSet = true;
}
Thread.Sleep(1000);
if (niSet)
{
Debug.Print("EthernetENC28J60 IP address has been set: IP = " + ni.IPAddress + " Subnet mask = " + ni.SubnetMask);
rc = true;
}
else
{
Debug.Print("Could not set EthernetENC28J60 IP address");
rc = false;
}
return rc;
}
void eth_CableConnectivityChanged(object sender, NetworkAvailabilityEventArgs e)
{
try
{
if (e.IsAvailable)
{
Debug.Print("PrototypeDevice.CableConnectivityChanged Event - Ethernet cable is connected");
CableConnectedEvent.Set();
}
else
{
Debug.Print("PrototypeDevice.CableConnectivityChanged Event - Ethernet cable is not connected");
}
}
catch (Exception ex)
{
KioskUtilities.LogException("PrototypeDevice.eth_CableConnectivityChanged() exception ", ex);
KioskUtilities.Reboot();
}
}
void eth_NetworkAddressChanged(object sender, EventArgs e)
{
try
{
Microsoft.SPOT.Net.NetworkInformation.NetworkInterface ni = eth.NetworkInterface;
Debug.Print("NetworkAddressChanged Event");
if (ni.IsDhcpEnabled)
Debug.Print("DHCP is enabled");
else
Debug.Print("DHCP is disabled");
Debug.Print("IP address = " + ni.IPAddress);
Debug.Print("Gateway address = " + ni.GatewayAddress);
Debug.Print("Subnet mask = " + ni.SubnetMask);
foreach (string address in ni.DnsAddresses)
{
Debug.Print("DNS address = " + address);
}
}
catch (Exception ex)
{
KioskUtilities.LogException("eth_NetworkAddressChanged() exception ", ex);
KioskUtilities.Reboot();
}
}