Client Socket cannot connect to running Socket server

后端 未结 3 2036
醉话见心
醉话见心 2021-01-22 17:18

I have Android client app that communicates with server using Socket.

On my development machine, SocketServer (server is also written in Java) i

相关标签:
3条回答
  • 2021-01-22 17:54

    Try using, Port Forwarding

    From command prompt at adb location,

    adb forward tcp:8666 tcp:8666

    The forward command to set up arbitrary port forwarding — forwarding of requests on a specific host port to a different port on an emulator/device instance. Here's how you would set up forwarding of host port 8666 to emulator/device port 8666:

    If this doesn't help then post your code and logcat errors.

    0 讨论(0)
  • 2021-01-22 17:57

    If I got it right: your socket server is running on a separate machine. You cannot use 127.0.0.1 to connect to that server through your Android phone as that is the local loop back address. Find your machine's IP address and use that instead.

    In case of using it on the emulator when you try to connect to the socket server running on your machine you still cannot use 127.0.0.1 as that is local loop back address for the Emulator.

    0 讨论(0)
  • 2021-01-22 18:05

    Is your Android code running in an emulator or on real hardware over WiFi? If you're running in an emulator, the IP address for your development machine would probably be 10.0.2.2 (see Android Developer Tools: Emulator).

    If your app is running on an Android phone connecting over WiFi, you have to specify your machine's IP address, not the loopback address.

    Also, when you say your SocketServer is listening at 127.0.1.1, are you binding to that interface? You shouldn't bind to the loopback if you're expecting connections from other interfaces.

    0 讨论(0)
提交回复
热议问题