Question

I recently developed a TCP Client-Server application using WPF and C# for Windows Desktop. Now, I'm thinking to port it to Windows 8 Metro App.

But, it seems that System.Net.Sockets namespace in not present in the SDK for Metro Apps. (So I cannot use TcpListener, TcpClient, etc) I could not find a working example, either.

Is it possible to create a TCP-IP Server as a Windows 8 Metro App (using some different approach)? Are there any third-party libraries (free and open-source, preferably) available to accomplish this?

Please help me. Thanks in advance.

Was it helpful?

Solution

It's recommended to use StreamSocket class instead.

Here is an Example from MSDN.


A socket provides send and receive over TCP and a StreamSocketListener will listen for incoming TCP connections.

Here is my Idea:

First we need a Instance of StreamSocketListener.

private StreamSocketListener _listener = new StreamSocketListener();

Then start the listener wire up a connection received event handler and bind the service name.

_listener.ConnectionReceived += listenerConnectionReceived;
await _listener.BindServiceNameAsync("localServiceName");

If the localServiceName parameter is an empty string, then the system will select the local TCP port on which to bind. MSDN

Now we have to recive the Connection:

        void listenerConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
        {
            Console.WriteLine(string.Format("Recive connection from {0}", args.Socket.Information.RemoteHostName.DisplayName));
        }

BTW: I did a lot of research for this and haven't time left (and a Windows 8 METRO Development Environment) to prof my ideas. Hope i get soon to this. It really bugs me. (German/English) ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top