FEZ Spider 套件上的 WSAENETDOWN SocketException

WSAENETDOWN SocketException on a FEZ Spider kit

我正尝试在 .NETMF 4.3 中为我的 FEZ Spider 工具包编写一个 TCP 服务器。

public partial class Program
{
    void ProgramStarted()
    {
        ethernetJ11D.NetworkInterface.Open();
        ethernetJ11D.UseStaticIP("192.168.0.8", "255.255.255.0", "192.168.0.1");
        Socket serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        EndPoint endPoint = new IPEndPoint(IPAddress.Any, 7777);
        serverSocket.Bind(endPoint);
        serverSocket.Listen(10);

        new Thread(() =>
        {
            while (true)
            {
                Debug.Print("Network up: " + ethernetJ11D.IsNetworkUp);//true
                Debug.Print("Network connected: " + ethernetJ11D.IsNetworkConnected);//true
                System.Net.Sockets.Socket clientSocket = serverSocket.Accept();//exception!
                new Thread(new Request(clientSocket).Process);
            }
        }).Start();
    }

serverSocket.Accept 方法抛出错误代码为 10050 的 SocketException。This 页面显示 WSAENETDOWN:网络已关闭。然而,ethernetJ11D 的属性表明连接已建立,我可以毫无问题地 ping 设备。我做错了什么?

编辑

当我尝试 运行 以下客户端时,我在 socket.Connect 调用中遇到了相同的异常。

ethernetJ11D.NetworkInterface.Open();
ethernetJ11D.UseStaticIP("192.168.0.8", "255.255.255.0", "192.168.0.1");
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("192.168.0.5"), 7777);
socket.Connect(endpoint);

Debug.Print("connected");
byte[] msg = new byte[] { 7, 77, 222 };
socket.Send(msg);

编辑 2

我尝试改为实现 UDP 客户端。也不行。

我已经解决了问题:

  1. IPAddress.Any更改为静态IP,例如IPAddress.Parse("192.168.0.8").
  2. 通过在它之前添加 Thread.Sleep(3000) 来延迟绑定。看来接口的网络设置配置需要一些时间。