Ok, I got it nearly. My problem: The udpclient is in blocking mode when
receiving data.
Is there a way of getting available bytes prior to call receive method?
Here is my code:
UdpClient udpClient = new UdpClient();
// broadcasts identification request message to the network
Byte[] sendBytes = Encoding.ASCII.GetBytes("0 1");
// set address to broadcast address and port to 8001
IPEndPoint RemoteIpEndPoint = new
IPEndPoint(IPAddress.Parse("255.255.255.255"), 8001);
// broadcast data
udpClient.Send(sendBytes, sendBytes.Length, RemoteIpEndPoint);
//IPEndPoint object will allow us to read datagrams sent from any source.
RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
// Blocks until a message returns on this socket from a remote host.
string returnData = String.Empty;
do
{
Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
returnData = Encoding.ASCII.GetString(receiveBytes);
MessageBox.Show(returnData);
} while (returnData != String.Empty);
// close udp client
udpClient.Close();
"Frank Esser" <Mi*****@nurfuerspam.de> schrieb im Newsbeitrag
news:ef****************@TK2MSFTNGP14.phx.gbl...
Hello!
I have got machines that answer a certain UDP broadcast request with
certain information about them.
Some years ago I wrote a VB6 application that just sent out this UDP
broadcast request and received all machine information to display all
available machines in a grid.
Now I want to write the same application in C# but so far with no success.
There is a udp client available in the .NET framework but how can I use it
for my purpose?
I think it must be a matter of not more than 10 lines of code but I did
not find a hint so far how to do it... Can anybody help?
Thanks!