/// <summary> /// 实例化TCP客户端。 /// </summary> internal TcpListenerClient(TcpListener listener, Socket socket) { if (socket == null) { throw new ArgumentNullException(nameof(socket)); } if (listener == null) { throw new ArgumentNullException(nameof(listener)); } Socket = socket; Handler = listener.Handler; DataSender = new SocketDataSender(this); DataReceiver = new SocketDataReceiver(this); Data = new Dictionary <string, object>(); this["RemoteEndPoint"] = socket.RemoteEndPoint; //创建Socket网络流 Stream = new NetworkStream(socket); //设置服务器 Listener = listener; //开始异步接收数据 SocketAsyncState state = new SocketAsyncState(); Handler.BeginReceive(Stream, EndReceive, state); }
/// <summary> /// 实例化TCP客户端。 /// </summary> public TcpClient() { Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); Handler = new SocketHandler(); Data = new Dictionary <string, object>(); DataSender = new SocketDataSender(this); DataReceiver = new SocketDataReceiver(this); }