Mr.Smithyyy
Mr.Smithyyy

Reputation: 1329

TcpClient does not contain a constructor that takes 2 arguments

I'm trying to make a simple program that connects to an irc client.

In another post on code review, I saw this line:

 using (var irc = new TcpClient(_server, _port))

I have attempted to use this in my application but I get the error

TcpClient does not contain a constructor that takes 2 arguments

According to the MSDN docs TcpClient Constructor it should take string server, int port parameters.

:

class IRCBot
{
    private readonly string _server;
    private readonly int _port;

    public IRCBot (string server, int port)
    {
        _server = server;
        _port = port;
    }

    public void ChannelConnect()
    {
        do
        {
            try
            {
                using (var irc = new TcpClient(_server, _port))

                // Rest of code
}

Upvotes: 0

Views: 883

Answers (1)

anserk
anserk

Reputation: 1320

If you are using .NET Core try this:

// Create the client.
TcpClient client = new TcpClient();
// Connect to the server.
await client.Connect​Async(​_server, _port);

https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.tcpclient.-ctor?view=netcore-1.1#System_Net_Sockets_TcpClient__ctor

Upvotes: 1

Related Questions