i want to send a private message to particular client by selecting number in comboBox. but had tried to code it but message still end up receive the message at every clients side 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.
Please help. Thank you very much.
here is the code i tried, but doesn't work
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);
}
}