转载请标明出处~~
以下为Socket服务端关键代码,已测试OK
Thread serverThread;
Thread clientThread;
TcpListener serverTcp;
TcpClient clientTcp;
#region Socket读取数据
private void ServerStart()
{
//创建IPEndPoint实例
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 6001);
/*
//创建一个套接字
serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//将所创建的套接字与IPEndPoint绑定
serverSocket.Bind(ipep);
//设置套接字为收听模式
serverSocket.Listen(10);
*/
serverTcp = new TcpListener(ipep);
serverTcp.Start();