Exemplo n.º 1
0
        private void BtnSend_Click(object sender, EventArgs e)
        {
            string sendContent = TxtMsg.Text;

            if (sendContent.Length < 1)
            {
                return;
            }
            if (ChkLbClients.Items.Count < 1)
            {
                return;
            }

            try
            {
                byte[] sendBytes = Encoding.Default.GetBytes(sendContent);

                for (int i = 0; i < ChkLbClients.Items.Count; i++)
                {
                    IntPtr connId = (IntPtr)Convert.ToInt32(ChkLbClients.Items[i]);
                    if (ChkLbClients.GetItemChecked(i))
                    {
                        _server.Send(connId, sendBytes, sendBytes.Length);
                    }
                }

                TxtMsg.Text = string.Empty;
            }
            catch (Exception exc)
            {
                AddLog($"发送失败:{exc.Message}");
            }
        }
Exemplo n.º 2
0
        private void BtnDisConnection_Click(object sender, EventArgs e)
        {
            if (ChkLbClients.Items.Count > 0)
            {
                try
                {
                    for (int i = 0; i < ChkLbClients.Items.Count; i++)
                    {
                        IntPtr connId = (IntPtr)Convert.ToInt32(ChkLbClients.Items[i]);

                        if (ChkLbClients.GetItemChecked(i))
                        {
                            _server.Disconnect(connId, true);
                        }
                    }
                }
                catch (Exception exc)
                {
                    AddLog(exc.Message);
                }
            }
        }