Thread threadWatch = null; // 负责监听客户端连接请求的 线程;
Socket socketWatch = null;
Dictionary<string, Socket> dict = new Dictionary<string, Socket>();//存放套接字
Dictionary<string, Thread> dictThread = new Dictionary<string, Thread>();//存放线程
//开启tcp监听
void start_tcp_scoket()
{
IPEndPoint newipep = new IPEndPoint(IPAddress.Any, 8000);
// 创建负责监听的套接字,注意其中的参数;
socketWatch = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
获得文本框中的IP对象;
//IPAddress address = IPAddress.Parse(get_loc_ip());
// 创建包含ip和端口号的网络节点对象;
//IPEndPoint endPoint = new IPEndPoint(address, 8000);
try
{
// 将负责监听的套接字绑定到唯一的ip和端口上;
socketWatch.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
socketWatch.Bind(newipep);
}
catch (SocketException se)
{
MessageBox.Show("异常:" + se.Message);
return;
}
// 设置监听队列的长度;
socketWatch.Listen(10000);
// 创建负责监听的线程;
threadWatch = new