private void timer1_Tick(object sender, EventArgs e) { sm.Initialization(); tm.execute_rw(); if (TemplateManage.keys != null && TemplateManage.keys.Count > 0) { foreach (var item in TemplateManage.keys) { var ss = SocketStoreManager.Find(item); ss.sc.Send(PackData("3")); } TemplateManage.keys.Clear(); } if (TemplateManage.rwlb != null && TemplateManage.rwlb.Count > 0) { if (TemplateManage.dqrw != null) { this.label3.Text = "任务队列:" + TemplateManage.rwlb.Count + "****当前任务:" + TemplateManage.dqrw.mbid + "***任务状态:" + TemplateManage.dqrw.zt; } } else { this.label3.Text = "任务队列:0"; } //tm.tt(); }
private void thread() { while (islistening) { byte[] buffer = new byte[1024]; timer1.Start(); try { listener1.Bind(new IPEndPoint(IPAddress.Any, port)); listener1.Listen(2000); Console.WriteLine("等待客户端连接...."); while (true) { Socket sc = listener1.Accept();//接受一个连接 SocketStore ss = new SocketStore(); ss.key = sc.RemoteEndPoint.ToString(); ss.sc = sc; ss.time = DateTime.Now; SocketStoreManager.Add(ss); this.sc = sc; Console.WriteLine("接受到了客户端:" + sc.RemoteEndPoint.ToString() + "连接...."); int length = sc.Receive(buffer);//接受客户端握手信息 sc.Send(PackHandShakeData(GetSecKeyAccetp(buffer, length))); sc.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(Recieve), sc); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } }
public Service() { this.FormClosed += Service_FormClosed; InitializeComponent(); sm = new SocketStoreManager(); tm = TemplateManage.ini(); init(); }