I moved it from my Netease blog...
When I practiced writing the socket of window phone, I found a strange problem. The simulator can connect to the computer server through socket. However, when using a USB-connected hardware (HTC t8788), it was found that it could not interact with the computer server through socket. The computer confirmed that Zune was on. The mobile phone can also access the Internet from the computer through USB cable. But there is a problem with the socket connection ..
After research, it was discovered that it was a problem with the computer server. A common window written in C # On the computer serverProgram. A problem occurred when creating the socket to bind. I am bound to a local IP address.
Ipendpoint localep = new ipendpoint (iphostinfo. Addresslist. First (), 8888 );
In this way, you can connect to the simulator. The connected IP address is also the local IP address. However, a problem occurs when the hardware phone is deployed. It cannot be connected at all. You can only find it after multiple attempts.
The IP address simulator bound to the local machine can be connected, but the mobile phone cannot be connected through USB cable.
When binding 127.0.0.1, the mobile phone can be connected through a USB cable. However, the simulator cannot be connected.
Therefore, you cannot directly bind the local IP address or 127.0.0.1, And the IP address connected to the mobile app must also be the local IP address.
Computer server ipsettings:Int Port = convert. toint32 (tbport. Text); ipendpoint endpoint = new ipendpoint (IPaddress. Any, Port); // bind a random local IP address. _ Socket. BIND (endpoint );
Mobile phone interface:
In this way, both the simulator and the client deployed on the mobile phone can interact with the server on the computer through socket.