locked
Inter process communication using Datagram Sockets

    Question

  • Hello,

       We are writing a test app(windows store app in C#) which displays data sent from a middle ware layer. Previously we have implemented this using Sockets using MFC; now we are writing a Windows Store app version of the app. Apparently this is not working as we are not getting the callback from the middle ware; the MFC app however works perfectly fine. Is there something specific that needs to be taken care of in the case of Windows Store app? Or is this sort of communication not possible in Windows Store apps?

    P.S: We made sure the MFC app has exited to avoid two processes listening to the same local port.


    Haresh

    Friday, October 3, 2014 6:00 PM

Answers

  • Is your server running as a Modern app or is it a desktop app? If it is a modern app which uses the DatagramSocket class for listening on the loopback IP, then you will not be able to receive the packets over the loopback address unless your calling app (client) is the same as the receiving app (server):

    See the following note in this link: http://msdn.microsoft.com/en-us/library/windows/apps/hh780593.aspx

    ...Windows Runtime app that uses a DatagramSocket or StreamSocketListener to listen on an IP loopback address is prevented from receiving any incoming packets....

    CheckNetIsolation is useful only for opening the ports for client side apps which are trying to connect to a localhost address (where the localhost address is not a Windows Store app, the server side code must be a desktop app if you want to listen on the loopback address).


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Tuesday, October 7, 2014 4:56 PM
    Moderator
  • A WinRT - modern app listener server can only receive incoming packets from clients if it is listening on any address other than the loopback address.

    You cannot write a server that listens and tries to receive packets on the loopback address from a "different" client app.


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Thursday, October 9, 2014 5:05 PM
    Moderator

All replies

  • Where is the server component running? On the same system as the Windows Store app or somewhere else? If it is hosted in your "Private Network" did you enable the appropriate "Capablities" in the package.appxmanifest of your Windows Store app?

    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Friday, October 3, 2014 10:08 PM
    Moderator
  • I had enabled Private Networks(Client and Server). Also the server is on the same machine. still I don't get a callback to Message Received. Also its not throwing an exception and going into catch block.
    Monday, October 6, 2014 6:00 AM
  • I am using the following code to listen to a UDP port:-

    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");
            }

    Monday, October 6, 2014 12:04 PM
  • I am not getting a callback on Message_Received().  It is not throwing any exception but no reply as well. Can you please let me know if anything is missing

    Thanks in Advance

    Monday, October 6, 2014 12:05 PM
  • See these links for further details:

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/JJ835817(v=win.10).aspx

    http://msdn.microsoft.com/en-us/library/windows/apps/hh780593.aspx

    For Windows Store apps released to the Store, Network loopback is disabled by the firewall policy. However, if you want to side-load the app for internal usage and not publish the app to the Store, you can use the CheckNetIsolation utility (second link above, see LoopbackExempt) to enable loopback communication between your Windows Store app and the Socket server.


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Monday, October 6, 2014 5:58 PM
    Moderator
  • 1) Thanks a lot for the response. Since I am running the app from Visual studio its already added under loopback exceptions. I also confirmed it by running the following command-

    CheckNetIsolation.exe LoopbackExempt -s

    2) I also tried this small exercise where I modified the SDK sample of DatagramSocket itself. I changed the port to listen to the specific port I am interested in, and no messages callback here too. The SDK sample works only when message is sent from step 3) Its own client.

    Tuesday, October 7, 2014 4:15 AM
  • Is your server running as a Modern app or is it a desktop app? If it is a modern app which uses the DatagramSocket class for listening on the loopback IP, then you will not be able to receive the packets over the loopback address unless your calling app (client) is the same as the receiving app (server):

    See the following note in this link: http://msdn.microsoft.com/en-us/library/windows/apps/hh780593.aspx

    ...Windows Runtime app that uses a DatagramSocket or StreamSocketListener to listen on an IP loopback address is prevented from receiving any incoming packets....

    CheckNetIsolation is useful only for opening the ports for client side apps which are trying to connect to a localhost address (where the localhost address is not a Windows Store app, the server side code must be a desktop app if you want to listen on the loopback address).


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Tuesday, October 7, 2014 4:56 PM
    Moderator
  • Hello Prashant,

    Thanks for the response. 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 of 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 from other client message sending apps?

    Thanks in Advance

    Thursday, October 9, 2014 12:22 PM
  • A WinRT - modern app listener server can only receive incoming packets from clients if it is listening on any address other than the loopback address.

    You cannot write a server that listens and tries to receive packets on the loopback address from a "different" client app.


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Thursday, October 9, 2014 5:05 PM
    Moderator