locked
Tracing UDP broadcast packets RRS feed

  • Question

  • Good morning,
    I have a problem running a piece of code under Windows 7.

    I have an hardware device plugged in my LAN. This device sends broadcast UDP packets, containing some information about it (its name, its ip address and so on).
    I wrote a simple test application (using .Net fx 3.5 and WPF) that sets up a socket and start listen for these packets in asynchronous mode.
    This piece of code works well under Windows XP SP2 (or SP3), but when I try to run it under Windows 7 I see nothing. I checked the firewall rules, and I removed all restrictions to my application, but the problem still remains.

    The test application code is very simple: this is what I do on class constructor (30002 is the port number we decided the device must use to communicate inside our LAN, and 84 is the length of the packet sent by the device)

    EndPoint endPoint = new IPEndPoint(IPAddress.Any, 30002);
    this._socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
    this._socket.Bind(endPoint);
    this._udpBuffer = new Byte[84];
    this is what I do in response of a Button click on my application (to start listen to packets)

    EndPoint endPoint = new IPEndPoint(IPAddress.Any, 30002);
    this._socket.BeginReceiveFrom(this._udpBuffer, 0, 84, SocketFlags.None, ref endPoint, new AsyncCallback(this.PacketReceived), null);
    and this is the code of PacketReceived callback

    EndPoint endPoint = new IPEndPoint(IPAddress.Any, 30002);
    this._socket.EndReceiveFrom(result, ref endPoint);
    
    // do something to track packets...
    
    // restart listening
    this._socket.BeginReceiveFrom(this._udpBuffer, 0, 84, SocketFlags.None, ref endPoint, new AsyncCallback(this.PacketReceived), null);
    As I said before, if I run this simple application under XP, everything goes well, and I see my packets as they arrive. On the contrary, when I run it under Windows 7 64bits, I see no packets. I did no test under Windows 7 32 bits (as we don't have any machine running it).
    To be more complete, I'm quite sure it's not a problem of the device, since if I use a sniffer program to trace network activity under Windows 7, I see all my UDP broadcast packets.

    Thanks in advance for the help, and sorry for my English.

    Marco Stevanato
    Aprilia Racing S.r.l.
    Thursday, November 26, 2009 8:42 AM

Answers

  • I solved the problem.

    I found out that the device packets were sent to 10.255.255.255.
    When I changed the destination address to 10.1.255.255 (consider that devices ip are on form 10.1.*.* with subnet mask 255.255.0.0), everything started to work both in Vista and 7.
    Since the program worked fine under XP, I guess what might be changed on the two newer O.S. ...

    Bye
    • Marked as answer by marcostewa Thursday, January 14, 2010 10:16 AM
    Thursday, January 14, 2010 10:15 AM

All replies

  • Hello

    The Socket class belongs to the System.Net namespace. We have a dedicated forum for any questions regarding System.Net.XXXX classes:

    http://social.msdn.microsoft.com/Forums/en-US/ncl/threads

    I will help you move the thread to that forum. There should be a lot of network experts there.


    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, November 27, 2009 12:42 PM
  • Sorry, I didn't see this forum.
    Thanks,

    Marco Stevanato
    Aprilia Racing S.r.l.
    Friday, November 27, 2009 12:47 PM
  • Hi,
       Is the firewall open on win7 64?Maybe  the UDP port is not open,or block by firewall,or by Rounter
    Tuesday, December 1, 2009 6:42 AM
  • Hi,
    I have checked Windows 7 firewall rules, and I saw that every UDP port and every TCP port is opened for my program. Besides, the OS doesn't block the packets, otherwise [I think] it shouldn't be possible to see them with the sniffer.
    I guess if it could be something concerning broadcast: it could be possible that the OS filters the packets for a security issue?
    Thanks
    Thursday, December 10, 2009 10:56 AM
  • I solved the problem.

    I found out that the device packets were sent to 10.255.255.255.
    When I changed the destination address to 10.1.255.255 (consider that devices ip are on form 10.1.*.* with subnet mask 255.255.0.0), everything started to work both in Vista and 7.
    Since the program worked fine under XP, I guess what might be changed on the two newer O.S. ...

    Bye
    • Marked as answer by marcostewa Thursday, January 14, 2010 10:16 AM
    Thursday, January 14, 2010 10:15 AM
  • I have a similar problem, can you share the solution ?
    Saturday, May 8, 2010 3:07 AM