private void worker_DoWork()
{
Thread.CurrentThread.Name = "Discovery Agent Thread.";
byte[] buffer = new byte[BUFF_SIZE];
string receivedInfoRaw;
string receivedInfo;
while(isStarted)
{
try
{
int numBytes = multicastSocket.Receive(buffer);
receivedInfoRaw = System.Text.Encoding.UTF8.GetString(buffer, 0, numBytes);
// We have to remove all of the null bytes if there are any otherwise we just
// take the whole string as is.
if (receivedInfoRaw.IndexOf("\0") != -1)
{
receivedInfo = receivedInfoRaw.Substring(0, receivedInfoRaw.IndexOf("\0"));
}
else
{
receivedInfo = receivedInfoRaw;
}
ProcessBrokerMessage(receivedInfo);
}
catch(SocketException)
{
// There was no multicast message sent before the timeout expired...Let us try again.
}
//We need to clear the buffer.
buffer[0] = 0x0;
ExpireOldServices();
}
}