日期:2014-05-17 浏览次数:21218 次
Socket socketWatch = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress address = IPAddress.Parse("172.16.10.47");
IPEndPoint endpoint = new IPEndPoint(address, 2000);
socketWatch.Bind(endpoint);
socketWatch.Listen(10);
MessageBox.show("服务端开始监听...");
Socket sokConnection = socketWatch.Accept(); //接收客户端连接请求
MessageBox.show("连接成功,客户端IP为:" + sokConnection.RemoteEndPoint.ToString()); //这里收到的总是客户端的有线IP
IPAddress address = IPAddress.Parse("172.16.10.47");
IPEndPoint endpoint = new IPEndPoint(address, 2000);
Socket socketClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socketClient.Connect(endpoint); //向服务端发送连接请求(这里默认就用了有线连接)
Socket socketClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress address = IPAddress.Parse("192.168.1.14");
IPEndPoint localIpPoint = new IPEndPoint(address, 0); //0表示绑定由本地系统自动分配的可用端口号
socketWatch.Bind(localIpPoint);
IPAddress server = IPAddress.Parse("172.16.10.47");
socketClient.Connect(server, 2000); //向服务端发送连接请求(这里默认就用了有线连接)