private void Login(object sender, EventArgs e) { if (open) { //创建监听线程 thread1 = new Thread(ListenSocket) { IsBackground = true }; thread1.Start(serverSocket); ClientLogin form1 = new ClientLogin(); form1.Client_Online += new Online(ShowClientList1); form1.Offline_Server += new OfflineOnServer(ShowClientList2); form1.Show(); } }
//点击开启服务器后 private void StartServer(object sender, EventArgs e) { if (!open) { if (first) { // 连接服务器后返回信息到信息表中 serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); textBox1.Text = GetLocalIP(); IPAddress ip = IPAddress.Parse(GetLocalIP()); IPEndPoint endPoint = new IPEndPoint(ip, int.Parse(textBox2.Text)); //绑定端口号 serverSocket.Bind(endPoint); //设置监听 serverSocket.Listen(100); ShowMsg("开启监听!"); first = false; } else { ShowMsg("服务器重新连接!"); for (int i = 0; i < ClientList_ID_temp.Length; i++) { //创建监听线程 thread1 = new Thread(ListenSocket) { IsBackground = true }; thread1.Start(serverSocket); ClientLogin form1 = new ClientLogin(ClientList_ID_temp[i]); form1.Client_Online += new Online(ShowClientList1); form1.Offline_Server += new OfflineOnServer(ShowClientList2); form1.Show(); } } open = true; isAccident = false; } }