locked
DatagramSocket listener is NOT getting MessageReceived call back

    Question

  • Hello,

    1) I am trying to listen a UDP port using DatagramSocket in a WinRT app. The server is in the same machine. Also I have enabled the capability Private Networks(Client & Server). I am using the following code below to achieve this:-

    DatagramSocket listener = new DatagramSocket();
    listener.MessageReceived += Message_Received;
    HostName windowsHostname = new HostName("127.0.0.1");
                try
                {
                    await listener.BindEndpointAsync(windowsHostname, "port_number");
                    //await listener.ConnectAsync(windowsHostname, "port_number");
                    // await listener.BindServiceNameAsync("port_number");
                    Debug.WriteLine("After calling async bind");
                }
                catch(Exception exception)
                {
                    Debug.WriteLine("inside catch");
                    Debug.WriteLine("exception.HResult. {0}", exception.HResult.ToString()); 
                    if(SocketError.GetStatus(exception.HResult) == SocketErrorStatus.Unknown)
                    {
                        Debug.WriteLine("inside throw");
                        throw;
                    }
                }
    
    
    async void Message_Received(DatagramSocket socket, DatagramSocketMessageReceivedEventArgs eventArguments)
            {
                Debug.WriteLine("inside Message_Received");
            }

    In the try block as you can see, I tried using all 3 bind methods, still no reply on Message_Received. I don't get any exception or any output log though. There is one more test app using MFC which is working fine (listening gets message callbacks).

    Can you please let me know what could be missing OR is it possible at all with this.

    2) I also tried to modify the SDK sample given my MSDN for DatagramSockets, (DatagramSocket sample)

    And changed the port number to my desired port number, still I don't get a call back. The SDk sample gets messages only from its own clients "hello" message in step 3.

    Please throw some light on the same.

    Thanks in Advance


    • Edited by Pooja L Monday, October 6, 2014 12:21 PM
    Monday, October 6, 2014 12:20 PM

Answers

  • DatagramSocket does not allow datagram from other processes running in the same machine, not even when enabling loopback exemptions, unless the datagram comes from the same app. 

    It is different when sending datagrams. Sending datagramas to other processes running in the same machine is allowed ONLY when loopback exemptions are enabled, for testing purposes.

    Tuesday, October 14, 2014 3:24 PM

All replies

  • Do you know if this works when the server is on a different machine?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, October 6, 2014 7:09 PM
    Moderator
  • I haven't verified with different machine. But I have tried the following tests:-

    The listener(server) is the modern app(code given in the above post).

    I have a client in MFC app, which sends messages. I am trying to sent this message to the modern app(server) over loopback but messageReceived isn't called on the winRt modern app side.

    I have also verified if my MFC client app is working fine by writing a MFC server for it. In this case messages are received by the MFC server listener app.

    My question is is this communication possible ? WinRT(modern app) listener server and  other client message sending apps?

    Thanks in advance

    Thursday, October 9, 2014 12:42 PM
  • Post your app to OneDrive and share a link here - I'll check it out.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, October 9, 2014 1:21 PM
    Moderator
  • DatagramSocket does not allow datagram from other processes running in the same machine, not even when enabling loopback exemptions, unless the datagram comes from the same app. 

    It is different when sending datagrams. Sending datagramas to other processes running in the same machine is allowed ONLY when loopback exemptions are enabled, for testing purposes.

    Tuesday, October 14, 2014 3:24 PM