/// <summary>
 /// 发送文本
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button2_Click(object sender, EventArgs e)
 {
     TCPServerManager manager = new TCPServerManager(_server_id);
     foreach (DataGridViewRow row in dataGridView1.Rows)
     {
         manager.Send(Msg.Zmsg1, Encoding.Unicode.GetBytes(textBox2.Text), row.Tag as TCPEndPoint);  //给在线用户同步发送文本
     }
 }
        /// <summary>
        /// 关闭服务器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            TCPServerManager manager = new TCPServerManager(_server_id);
            manager.Stop();  //结束服务器侦听

            foreach (DataGridViewRow r in dataGridView1.Rows)  //断开每个终端 数据接收终止
            {
                (r.Tag as TCPEndPoint).TryClose();
            }
            //注销事件

            Close();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (TCPServerManager.ServerExist(textBox2.Text))
            {
                MessageBox.Show("服务器已存在!");
                return;
            }

            TCPServerManager manager = new TCPServerManager(textBox2.Text);  //创建服务器
            manager.Start(int.Parse(textBox1.Text)); //启动服务器

            frmTCPServer frmtcpserver = new frmTCPServer(textBox2.Text, int.Parse(textBox1.Text));
            frmtcpserver.Show();
        }
        /// <summary>
        /// 发送图片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter = "图片文件|*.jpg;*jpeg";
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    textBox3.Text = ofd.FileName;
                    Image image = Image.FromFile(textBox3.Text);
                    using (MemoryStream ms = new MemoryStream())
                    {
                        image.Save(ms, ImageFormat.Jpeg);

                        TCPServerManager manager = new TCPServerManager(_server_id);
                        foreach (DataGridViewRow r in dataGridView1.Rows)
                        {
                            manager.SendAsync(Msg.Zmsg2, ms.ToArray(), r.Tag as TCPEndPoint, null);  //给在线用户异步发送图片
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 窗体加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmTCPServer_Load(object sender, EventArgs e)
        {
            Text = "TCPServer " + _server_id + ":" + _port;

            //注册事件
            TCPServerManager manager = new TCPServerManager(_server_id);  //访问_server_id服务器
            manager.TCPMessageReceived += new TCPMessageReceivedEventHandler(manager_TCPMessageReceived);
            manager.TCPClientConnected += new TCPClientConnectedEventHandler(manager_TCPClientConnected);
            manager.TCPClientDisConnected += new TCPClientDisConnectedEventHandler(manager_TCPClientDisConnected);
            manager.TCPClientDisConnected4Pulse += new TCPClientDisConnected4PulseEventHandler(manager_TCPClientDisConnected4Pulse);
        }