How to bind to computer's IP port on Android Emulator?
I use these codes to make it listen to the local port of 56789. And I make a program on another computer at the same intranet.Trying to connect it at that place but it times out. So the real question is why dealing binding port this way is not proper.Thank you!
try
{
ServerSocket ss=new ServerSocket(56789);
开发者_运维知识库 System.out.println("before accpet!");
Socket s=ss.accept();
System.out.println("accpet!");
}
catch(Exception e){
e.printStackTrace();
}
Looking at the Android documentation for ServerSocket, it sounds like it is binding to the localhost 127.0.0.1 address by default. If this is the case, you should be binding to the external IP address of the emulator instead, which can be retrieved via NetworkInterface. Keep in mind that the IP address of the emulator is different from the IP address of your host machine.
精彩评论