2015-10-08 34 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主機。

相關問題