locked
Can't seem to listen and send data on the same DatagramSocket

    Question

  • Hi,

    I am having real issues trying to get my Windows Phone / Store App to listen on a port and send data on the same port. What I want to do seems quite simple:

     - Connect and listen for UDP messages on port 12345

     - Send messages to a device on port 12345, I would expect the device to send a response back to 12345

     - Process the response from the device

    If I create single DatagramSocket and listen and bind to 12345, then send the message to 12345 the response never makes it back into my code.  Using Wireshark I have verified that the response is being sent back (both source and destination ports are 12335) but it never calls the MessageRecieved callback.  This is my simplified code:

       DatagramSocket socket = new DatagramSocket();

       socket.MessageReceived += MessageRecieved;

       await socket.BindServiceNameAsync("12345");

       await socket.ConnectAysnc(new HostName("1.2.3.4), "12345");

       DataWrtier writer = new DataWriter(socket.OutputStream);

       writer.WriteString("hello");

       await writer.StoreAsync(); 

    The message is sent and I can see the response coming back on the wire but nothing comes back into my code.

    Any help would be greatly appreciated.

    Thanks

    Stu

     

    Wednesday, September 10, 2014 11:26 PM

All replies

  • Please provide a client and server app, and I'll test this 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, September 11, 2014 7:36 PM
    Moderator