iko79
iko79

Reputation: 1258

How to create a System.Net.Sockets.Socket instance for Windows Phone 8.1 App

this may be a stupid question since I am completely new to Windows Phone development - I've got some experience with developing in C# though... Anyways, I cannot figure out what is going on and MSDN is confusing me, maybe I got it all wrong.

I am simply trying to send UDP datagrams from a Lumia 925 to my PC, so I created an empty Windows Phone 8.1 app via VS wizard (MSVS 2015). Now, MSDN says there's supposed to be a socket class for Windows Phone 8.1, but there isn't even a Sockets namespace in System.Net. Now I tried my luck with DatagramSockets, which, according to MSDN, should feature a method GetEndpointPairsAsync, but it doesn't.

I thought maybe I'm missing assemblies I'd have to add to the References, but in the Add References dialog, there is hardly anything to be found. I'm starting to think that I missed out something very fundamental.

I'd appreciate any ideas.

Upvotes: 0

Views: 291

Answers (1)

Rita Han
Rita Han

Reputation: 9720

Yes, you need use Windows.Networking.Sockets instead of System.Net.Sockets. (Reference)

As for GetEndpointPairsAsync() you may try this:

    async Task ListEndpoints()
    {
        HostName host = new HostName("www.stackoverflow.com");
        var eps = await DatagramSocket.GetEndpointPairsAsync(host, "80");
        foreach (EndpointPair ep in eps)
        {
            System.Diagnostics.Debug.WriteLine("EP {0} {1}", new object[] { ep.LocalHostName, ep.RemoteHostName });
        }
    }

More information is here.

Upvotes: 1

Related Questions