2017-08-09 61 views
0

所以我想在C#中使用一些服務器客戶端組件,但在使用TCPClient時遇到了問題。當實例化它時,我似乎無法訪問按照documentation接受字符串和int的構造函數。爲什麼會發生這種情況,我該如何解決?TCPClient no構造函數需要兩個參數

using System; 
using System.Net.Sockets; 
using System.Text; 

namespace Client 
{ 
    internal class Client 
    { 

     private readonly int PORT = 2500; 
     private readonly string IP = "127.0.0.1"; 

     public Client() 
     { 

      TcpClient client = new TcpClient(IP, PORT); 
+0

什麼框架版本?你在使用Core嗎? UWP? – Amy

+1

該代碼爲我編譯。您定位的是哪個版本的.NET?另外,我強烈建議您避免給命名空間和類使用相同的名稱,並遵循.NET命名約定。 (PORT和IP應該是'const','PORT'應該叫'Port'。) –

回答

0

看來你有我的問題,我解決了。所以試試這個:

TcpClient client = new TcpClient(); 
await client.Connect​Async(​IP, PORT); 

我猜你正在使用.NET Core。我希望對你有所幫助:)

相關問題