Create port issues with ServerSocket in Android

Source: Internet
Author: User


==================== Problem Description ====================
A service port was created in activity through New ServerSocket (9090), why is the port not open when viewed through the netstat command?
And then at the client anyway also connected not on that sure
Code:
Server=new ServerSocket (12345);
System.out.println ("IP:" +server.getlocalsocketaddress () + "----Port:" +server.getlocalport ());
SYSTEM.OUT.PRINTLN ("Server IP:" +server.getinetaddress ());
SYSTEM.OUT.PRINTLN ("Server Build Success ************");
In the LOGCAT can see "Server build Success" and so on all the output, all normal, but there is no real open port

However, if you create the ServerSocket object directly in the application program, you can open the port and the client connection is normal.
Ask for advice!!!
Note:
Network permissions in manifest have been added.
<uses-permission
Android:name= "Android.permission.INTERNET" ></uses-permission>
<uses-permission
Android:name= "Android.permission.ACCESS_NETWORK_STATE" ></uses-permission>

==================== Solution 1====================
The port on the emulator is not a port on the PC, and the two need to be mapped

Map the native port tcp/6100 to the emulator tcp/7100 port (UDP is the same).
>adb–s emulator-5554 forward tcp:6100 tcp:7100

Creating port Problems with ServerSocket in Android

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.