我有一个Windows Universal Application应该充当TCP服务器.
m_Listener = new StreamSocketListener();
m_Listener.ConnectionReceived += (s, e) => ProcessRequestAsync(e.Socket);
var bind = m_Listener.BindServiceNameAsync("8080").Wait();
Run Code Online (Sandbox Code Playgroud)
在启动应用程序之前,端口没有绑定到任何东西:
C:\Users\jsant>netstat -a | grep 8080
^C (Cancelled after some seconds because no reasults were found)
Run Code Online (Sandbox Code Playgroud)
然后,当我启动应用程序时:
C:\Users\jsant>netstat -a | grep 8080
TCP 0.0.0.0:8080 Laptop:0 LISTENING
Run Code Online (Sandbox Code Playgroud)
套接字正在我的电脑上听!试图以某种方式访问它会导致错误
C:\Users\jsant>telnet 127.0.0.1 8080
Connecting To 127.0.0.1...Could not open connection to the host, on port 8080: Connect failed
C:\Users\jsant>telnet 192.168.1.167 8080
Connecting To 192.168.1.167...Could not open connection to the host, on port 8080: Connect failed
C:\Users\jsant>telnet Laptop …Run Code Online (Sandbox Code Playgroud)