The mobile phone interacts with the computer server through a socket through USB

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.