2015-10-08 37 views
1

我得到了下面的代码:的TcpClient抛出SocketException

public static readonly IPEndPoint RootNode = new IPEndPoint(IPAddress.Parse("213.226.18.82"), 8333); 

public static void Main(string[] args) 
{ 
    TcpClient tcpClient = new TcpClient(RootNode); 
} 

这将引发与消息The requested address is not valid in its context一个SocketException。 现在什么奇怪的是,此代码:

public static readonly IPEndPoint RootNode = new IPEndPoint(IPAddress.Parse("213.226.18.82"), 8333); 

public static void Main(string[] args) 
{ 
    TcpClient tcpClient = new TcpClient(); 

    tcpClient.Connect(RootNode); 
} 

的区别是什么吗?

+0

连接有两个端点。本地和远程。第一个代码应该设置一个本地端点,而第二个代码设置远程端点。 – jdweng

回答

0

constructor

初始化TcpClient类的新实例,并将其绑定到指定的本地端点。

Connect method

连接客户端使用指定的远程网络端点的远程TCP主机。

相关问题