套接字未与IPEndPoint连接

时间:2014-06-10 04:35:19

标签: c# networking

我有一个System.Net.Sockets.Socket连接到后端。

public class Connection
{
    private readonly Socket _client;
    private readonly IPEndPoint _endPoint;

    byte[] _sendBuf = new byte[0x1000];

    protected Connection(string host, int port)
    {
        var ipAddress = IPAddress.Parse(host);
        _endPoint = new IPEndPoint(ipAddress, port);
        _client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    }

    protected void Connect()
    {
        //Fails
        _client.Connect(_endPoint);
    }
}

套接字尝试连接但在调用Connect函数时超时。但是,如果我将hostport参数提供给Socket.Connect函数而不是IPEndPoint,那么它会成功连接。

    protected void Connect()
    {
        //Connects
        _client.Connect(host, port);    //same as used in creating IPEndPoint above
    }

为什么呢?我尝试连接的终点是与我所在网络的VPN。

0 个答案:

没有答案