System.Net.Sockets.Socket.Connect C# (CSharp) Method

Connect() public method

public Connect ( IPAddress address, int port ) : void
address System.Net.IPAddress
port int
return void
        public void Connect(IPAddress address, int port)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Enter(this, address);

            if (CleanedUp)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            if (!TcpValidationHelpers.ValidatePortNumber(port))
            {
                throw new ArgumentOutOfRangeException(nameof(port));
            }
            if (!CanTryAddressFamily(address.AddressFamily))
            {
                throw new NotSupportedException(SR.net_invalidversion);
            }

            IPEndPoint remoteEP = new IPEndPoint(address, port);
            Connect(remoteEP);
            if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
        }

Same methods

Socket::Connect ( EndPoint remoteEP ) : void
Socket::Connect ( string host, int port ) : void

Usage Example

Example #1
0
        public void ConnectHost(string host, int port)
        {
            _tcpSock.Connect(host, port);

            if (_tcpSock.Connected)
            {
                if (ClientConnected != null)
                {
                    ClientConnected(this, null);
                }
            }
        }
All Usage Examples Of System.Net.Sockets.Socket::Connect