Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is it possible to Android Emulator will be socket server and Windows form app will be client and they communicate each other?

My emulator IP address is 192.168.232.2 but i cannot ping from my pc and i cannot connect via my winform app

What can i do?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
197 views
Welcome To Ask or Share your Answers For Others

1 Answer

When creating a ServerSocket in your Android code, you can assign a port to it by passing it, for example here I'm opening a ServerSocket on the port 8080:

    val serverSocket = ServerSocket(8080)

You then need to use adb to forward incoming connection to your emulator, by running, here forwarding the port 8080 again

adb forward tcp:8080 tcp:8080

At this point any connection to your PC on port 8080 will be forwarded to your emulator.

You can get the IP by typing in the terminal ifconfig or ipconfig depending on your operating system.

The easiest way to test it is to run both client and server on your PC and just use localhost or 127.0.0.1 as the IP address.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...