tags:

views:

87

answers:

1

I have an array of ip address which contains a set of ip address, which is to be communicated from server. Example: There are 5 clients. 4's Ip address out of this 5 will be stored in an ip address array. The remaining one will be blocked at the time of sending messages from server. How it will be done. My sending message Code is shown below.

private void buttonSendMsg_Click(object sender, EventArgs e)
    {

        try
        {

                Object objData = richTextBoxSendMsg.Text;
                byData = System.Text.ASCIIEncoding.ASCII.GetBytes(objData.ToString());
                for (int i = 0; i < m_clientCount; i++)
                {
                    if (m_workerSocket[i] != null)
                    {
                        if (m_workerSocket[i].Connected)
                        {

                            m_workerSocket[i].Send(byData);

                        }
                    }
                }
            }


        catch (SocketException se)
        {
            MessageBox.Show(se.Message);
        }
    }
A: 

Try implementing an array of n+1 size, where n is the number client IP addresses. Keep a position in the array as the "blocked" client (preferably the first or last index). So, your code will end up something like this:

if (m_workerSocket[i].Connected)
{
    clientIp[0] = m_workerSocket[i]; //index 0 is the blocked client
    clientIp[indexOf(m_workerSocket[i])] = null;
    m_workerSocket[i].Send(byData);

}

After this, revert your clientIp array state, setting mWorkerSocket[i]'s value at it's original position and null at position 0. You'll need a method that will be constantly checking this array in order to block the client at index 0 while is sending data somehow.

Rigo Vides