I want to send a private message to particular client by selecting number in comboBox. but had tried to code it but message still receive at every clients that connected to server. i want to send the message using the worker socket object stored in ArrayList, but don't know how to get it correct.
Any help will be appreciated, thanks.
Any help will be appreciated, thanks.
Code:
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; Convert.ToInt32(comboBox1.SelectedItem); if (comboBox1.SelectedIndex != 0) { MessageBox.Show("Please Choose a Connected User no."); return; } for (int i = 0; i < m_workerSocketList.Count; i++) { comboBox1.SelectedItem = m_workerSocketList[i]; // workerSocket = (Socket)m_workerSocketList[i]; if (workerSocket != null) { if (workerSocket.Connected) { workerSocket.Send(byData); } } } } catch (SocketException se) { MessageBox.Show(se.Message); } }
Comment