haan jae

haan jae

  • NA
  • 22
  • 27.1k

Send message to Specific Client by selecting number in comboBox

Nov 30 2011 11:24 PM
Updated:

i modified the code, now can send private message by selecting number of client in comboBox, this is done when i remove the for loop coz if use the for loop, total messages will be sent at once depends on total number of clients connected.

but still have problem that when any client disconnect and reconnect again, private message cannot send anymore. 

Any help will be appreciated, thanks in advance. sorry and pls ask again if the explanation is unclear.

here is the code i tried:
        void indmsgbtn_Click(object sender, EventArgs e)
        {
            try
            {
                  
            string msg = richtxtindmsg.Text;            
            msg = "Private Admin Message: " + msg + "\n";
            byte[] byData = System.Text.Encoding.ASCII.GetBytes(msg);
            //Socket workerSocket = null;
           // for (int i = 0; i < m_workerSocketList.Count; i++)
            //{
              Socket workerSocket = (Socket)m_workerSocketList[comboBox1.SelectedIndex];
              if (workerSocket != null)
              {
                  if (workerSocket.Connected)
                  {
                   try
                          {
                              workerSocket.Send(byData);
                          }
                          catch (SocketException ex)
                          {
                              MessageBox.Show(ex.Message);
                          }
                  }
              }
           } 
            catch (SocketException se)
            {
                   MessageBox.Show(se.Message);
            }
        }


Answers (3)