IPAddress ip = IPAddress.Parse("192.168.8.14");
IPEndPoint serverpoint = new IPEndPoint(ip, 9000);
s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
s.Bind(iep);//指定、绑定本地ip和端口
s.Connect(serverpoint);
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
IPEndPoint iep2 = s.LocalEndPoint as IPEndPoint;
Utils.WriteLogFile("本机地址2:" + iep2.Address.ToString() + "端口" + iep2.Port);//本机地址
Utils.WriteLogFile("连接状态:" + s.Connected);//本机地址
C# Socket TCP通信,连接服务器
本文转载:CSDN博客