我有一个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
函数时超时。但是,如果我将host
和port
参数提供给Socket.Connect
函数而不是IPEndPoint
,那么它会成功连接。
protected void Connect()
{
//Connects
_client.Connect(host, port); //same as used in creating IPEndPoint above
}
为什么呢?我尝试连接的终点是与我所在网络的VPN。