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);)
source share