问题
I am currently trying to make a socket connection from my client (iOS simulator) to my host (Genymotion simulator). I am having a hard time finding the correct IP address and configuring the right settings for VirtualBox to get this to work.
How can I find the proper IP address and port for iOS to connect to when I host the server on the Genymotion server?
回答1:
By default Genymotion devices use a NAT connection to connect to internet. It means they are not visible from your local network. You can change this connection to a Bridged connection. This type of connection will let your local DHCP gives the Genymotion device’s IP, then you will be able to reach it from everywhere on your local network.
To fix this, open VirtualBox app, choose the device you want to setup, open the settings > Network tab > Adapter 2 > Attached to: "Bridged Adaptor” instead of “NAT".
Then you need to get the local IP of the device. You can get it by running this command:
adb shell "ifconfig | awk '/inet addr/{print substr(\$2,6)}' | awk 'NR==2'"
Then you can connect to your device very easily using this IP, from everywhere in your local network.
We are working on making this really easier in the future. I'll update the post when this will be released.
来源:https://stackoverflow.com/questions/36392543/how-to-connect-a-socket-to-genymotion-device-that-is-hosting-a-server