Android Emulator UDP cannot receive; works fine on phone

后端 未结 1 838
醉酒成梦
醉酒成梦 2021-01-21 09:39

Hello I am trying to connect to a box that is on the network. It has a working UDP server on it. With the code below I am able to communicate with the box and send/receive UDP p

相关标签:
1条回答
  • 2021-01-21 10:03

    There is No Way you can connect your android emulator to any thing physical on your network directly.

    Android Emulator creates its own LAN and each emulator instance a new LAN instance with the same IPs (This is OK because they can't access each other)

    If you insist on using the Emulator to communicate with the Box , you should create a UDP proxy socket on your PC (Using JAVA , C# , C++ , VB ... or any desktop programming language you want)

    They way your Desktop App Will Work

    • get your LAN subnet to determain the packet source later.
    • Start a UDP Listener for the ports your server use.
    • Find the IP address of the sender (there are APIs for that) if the sender is the emulator, resend that packet to the box using the box IP

    There is a good demonistration on the subject on Android's developers website.

    Please take a look Here

    Good Luck

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