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

Connect() public method

public Connect ( IPEndPoint remoteEP ) : void
remoteEP IPEndPoint
return void
        public void Connect(IPEndPoint remoteEP)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Enter(this, remoteEP);
            if (_cleanedUp)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }
            if (remoteEP == null)
            {
                throw new ArgumentNullException(nameof(remoteEP));
            }

            Client.Connect(remoteEP);
            _active = true;

            if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
        }

Same methods

TcpClient::Connect ( IPAddress address, int port ) : void
TcpClient::Connect ( string hostname, int port ) : void

Usage Example

示例#1
1
		public void WorkerProcessMain(string argument, string passwordBase64)
		{
			int port = int.Parse(argument, CultureInfo.InvariantCulture);
			
			client = new TcpClient();
			client.Connect(new IPEndPoint(IPAddress.Loopback, port));
			Stream stream = client.GetStream();
			receiver = new PacketReceiver();
			sender = new PacketSender(stream);
			shutdownEvent = new ManualResetEvent(false);
			receiver.ConnectionLost += OnConnectionLost;
			receiver.PacketReceived += OnPacketReceived;
			sender.WriteFailed += OnConnectionLost;
			
			// send password
			sender.Send(Convert.FromBase64String(passwordBase64));
			
			receiver.StartReceive(stream);
			while (!shutdownEvent.WaitOne(SendKeepAliveInterval, false)) {
				Program.Log("Sending keep-alive packet");
				sender.Send(new byte[0]);
			}
			
			Program.Log("Closing client (end of WorkerProcessMain)");
			client.Close();
			shutdownEvent.Close();
		}
All Usage Examples Of System.Net.Sockets.TcpClient::Connect