Reputation: 167
Basically my code is only capturing part of the UDP protocol packet when I need it to get all of it.
UdpClient listener = new UdpClient(43965);
IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 43965);
long count = 0;
while(1 == 1)
{
if (listener.Available > 0)
{
byte[] data = listener.Receive(ref endpoint);
Console.WriteLine(Encoding.ASCII.GetString(data));
}
}
I'm getting (highlighted):
I should be getting:
Upvotes: 0
Views: 177
Reputation:
As Visual Vincent said, "MICS" is followed by 0x10 and then 0x00, so if you treat that part of the packet as a null-terminated string, it's "MICS\x10".
As you've discovered, you have to look at the raw bytes to find the data after it.
The data before it is the UDP header, the IP header, and the Ethernet header. You don't get those headers when reading from a UDP socket, you just get the UDP payload.
Upvotes: 1