Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've written the below c# Multicast send/receive. It works fine, but after hours and hours of researching and attempting multiple methods, I have been unable to figure out how to receive all of my UDP payload.

C#
UdpClient udpBroadcast = new System.Net.Sockets.UdpClient(2362); 
IPEndPoint groupEp = new IPEndPoint(IPAddress.Parse("224.0.5.128"), 2362);
udpBroadcast.Connect(groupEp);

byte[] bData = new byte[] { 0x44, 0x49, 0x47, 0x49, 0x00, 0x01, 0x00, 0x06, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; //Magic Word
udpBroadcast.Send(bData, bData.Length);
udpBroadcast.Close();

UdpClient udpResponse = new System.Net.Sockets.UdpClient(2362);
IPEndPoint groupREp = new IPEndPoint(IPAddress.Any, 2362);

    Byte[] rMessage = new Byte[4096];
    rMessage = udpResponse.Receive(ref groupREp);
    string returnData = Encoding.ASCII.GetString(rMessage, 0, rMessage.Length);
    Console.WriteLine("Device discovered:");
    Console.WriteLine(groupREp.Address.ToString() + " Port:" + groupREp.Port.ToString());
    Console.WriteLine(returnData.ToString());

udpResponse.Close();


Below is the full response from the devices when the 'magic word' is sent, the only part I receive back via my code is the "DIGI" chunk (testing with Wireshark open).
0000  c8 60 00 ea ba 7c 00 40  9d 2d e0 77 08 00 45 00   .`...|.@ .-.w..E.
0010  00 9b 00 0d 00 00 40 11  39 f1 c0 a8 be 01 c0 a8   ......@. 9.......
0020  01 02 09 3a 09 3a 00 87  bb b6 44 49 47 49 00 02   ...:.:.. ..DIGI..
0030  00 77 01 06 00 40 9d 2d  e0 77 02 04 c0 a8 be 01   .w...@.- .w......
0040  03 04 ff ff ff 00 0b 04  c0 a8 be 01 06 01 00 0d   ........ ........
0050  14 50 6f 72 74 53 65 72  76 65 72 20 54 53 20 31   .PortSer ver TS 1
0060  36 20 4d 45 49 07 01 02  08 1d 56 65 72 73 69 6f   6 MEI... ..Versio
0070  6e 20 38 32 30 30 30 36  38 34 5f 54 20 30 38 2f   n 820006 84_T 08/
0080  31 38 2f 32 30 30 36 0e  04 00 00 03 03 13 04 00   18/2006. ........
0090  00 04 03 19 01 01 0f 04  00 00 00 00 10 04 00 00   ........ ........
00a0  00 00 12 01 10 0c 02 00  01                        ........ .  


I really need the whole deal, as mac address, ip, server settings, etc. are all stored there. I know how to read them, but I have no clue how to get at the whole data from c# on the Receive.

Any suggestions/help?
Posted
Updated 30-Dec-12 20:31pm
v5

1 solution

So during you run this code whireshark is showing the whole datagram, but your udpclinet isn't getting all? The rMessage also contains only that, or the decoded string is chunked only?

What you get is not a string, it is some sort of structure - thus decoding will fail. Try to map it to a structure, or extract the portions you need and decode them individually.

(Compare this with yours: http://lamahashim.blogspot.hu/2009/06/using-c-udpclient-send-and-receive.html[^])
 
Share this answer
 
v2
Comments
Aaron 007 31-Dec-12 4:54am    
Right, the rMessage only reveals DIGI while wireshark shows the whole dgram. This example looks promising..
Zoltán Zörgő 31-Dec-12 9:49am    
Look at my second paragraph: debug the rMessage array!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900