public void execute(TransferProtocol tp) { ServerColony.id = tp.serverId; ServerColony.SERVER_AES_KEY = tp.message; ServerColony.log("集群服务器认证完成,本服务器编号:" + ServerColony.id, Constant.info, Constant.infoColor); Server.thread.Start(); }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { ServerColony.runing = false; Thread.Sleep(500); if (ServerColony.socket != null) { ServerColony.socket.Close(); ServerColony.socket = null; } serverColony = null; this.快速关闭ToolStripMenuItem_Click(null, null); }
public void 快速启动ToolStripMenuItem_Click(object sender, EventArgs e) { if (!Server.runing) { if (lastStartTime == DateTime.MinValue) { lastStartTime = DateTime.Now; } else { int date = (int)((DateTime.Now.ToFileTime() - lastStartTime.ToFileTime()) / 10000); if (date < MaxTimeExec) { LogInfoMessage("系统不能在连续5秒内启动多次", Constant.error, Constant.errorColor); return; } lastStartTime = DateTime.Now; } lock (locker) { if (!Server.runing) { this.快速启动ToolStripMenuItem.Enabled = false; this.快速关闭ToolStripMenuItem.Enabled = true; try { Server.tcpListener = null; Server.thread = null; LogInfoMessage("系统快速启动中...", Constant.info, Constant.infoColor); Server.tcpListener = new System.Net.Sockets.TcpListener(new IPEndPoint(IPAddress.Parse(MainForm.ip), MainForm.port)); Server.thread = new System.Threading.Thread(Server.ListenerClient); Server.runing = true; if (serverColony == null && MainForm.isColony == true) { serverColony = new ServerColony(); } else if (MainForm.isColony == false) { Server.thread.Start(); } else if (serverColony != null && ServerColony.runing == true) { Server.thread.Start(); } systemToolStripStatus.Text = "服务器启动完成"; } catch (ArgumentNullException) { LogInfoMessage("请填写IP地址或者初始化TcpListener错误", Constant.error, Constant.errorColor); MessageBox.Show("请填写IP地址或者初始化TcpListener错误", "错误"); Server.runing = false; this.快速启动ToolStripMenuItem.Enabled = true; this.快速关闭ToolStripMenuItem.Enabled = false; Server.tcpListener = null; Server.thread = null; } catch (FormatException) { MessageBox.Show("IP地址格式错误", "错误"); LogInfoMessage("IP地址格式错误", Constant.error, Constant.errorColor); Server.runing = false; this.快速启动ToolStripMenuItem.Enabled = true; this.快速关闭ToolStripMenuItem.Enabled = false; Server.tcpListener = null; Server.thread = null; } catch { LogInfoMessage("请检查集群服务器错误", Constant.error, Constant.errorColor); Server.tcpListener = null; Server.thread = null; Server.runing = false; this.快速启动ToolStripMenuItem.Enabled = true; this.快速关闭ToolStripMenuItem.Enabled = false; } } } } else { LogInfoMessage("服务已经启动", Constant.error, Constant.errorColor); MessageBox.Show("服务已经启动", "警告"); } }