许多人有同样的问题,但是每个人的实现方式都不相同。

我在实施它时需要帮助。

void sendUsingTcp()
{
    try
    {
        Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(172.16.8.200), 8000);
        sock.Connect(endPoint);
        // code past this never hits because the line above fails
    }
    catch (SocketException err)
    {
        MessageBox.Show(err.Message);
    }
}


我也尝试了TCP客户端直接使用相同的错误结果:

void sendUsingTcp()
{
    try
    {
        using (TcpClient client = new TcpClient())
        {
            IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(172.16.8.200), 8000);
            client.Connect(endPoint);
            // code past this never hits because the line above fails
        }
    }
    catch (SocketException err)
    {
        MessageBox.Show(err.Message);
    }
}


我的电脑的IP地址是172.16.11.144

最佳答案

i)8000端口很有可能用于其他用途。选择另一个(大)数字,看看是否发生相同的情况
ii)使用回送地址连接到您自己的计算机-IPAddress.Loopback

09-11 03:34
查看更多