Windows 8 TCP Server XAML Application in C #

I recently developed a TCP Client-Server application using WPF and C # for Windows Desktop. Now I'm going to transfer it to the Windows 8 Metro app.

But it looks like the System.Net.Sockets namespace is missing from the Metro Apps SDK. (Therefore, I cannot use TcpListener, TcpClient, etc.) I also could not find a working example.

Is it possible to create a TCP-IP server as an application for Windows 8 Metro (using a different approach)? Are there third-party libraries available for this (free and open source, preferably)?

Please help me. Thanks in advance.

+4
source share
1 answer

Instead, StreamSocket is recommended.

Here is an example from MSDN.


The socket provides sending and receiving over TCP, and the StreamSocketListener will listen for incoming TCP connections.

Here is my idea:

First we need an instance of StreamSocketListener.

private StreamSocketListener _listener = new StreamSocketListener(); 

Then start the listener, attach the connection handler, and bind the service name.

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

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

Now we need to restore 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 did not have time (and the Windows 8 METRO Development Environment) to talk about my ideas. I hope I get to that soon. It bothers me a lot. (German / English);)

+2
source

Source: https://habr.com/ru/post/1488480/


All Articles