+3 votes

Hi,

I want to try making an two android devices connect each other and play game with passing data.
one device create an hotspot and other second device connect using wifi with created hotspot device.

How can achieve this one in Godot?
Provide me source code or any document to full-fill this one.

i try using PacketPeerUDP to pass packages but it's not work in devices.
use ip: 127.0.0.1 OR 192.198.0.10 OR connected device ip

Thank you.

Godot version 3.1
in Engine by (59 points)

1 Answer

+2 votes
Best answer

Use Godot's MultiplayerAPI as it's easier to setup and you don't have to bother with low level stuff like sending and polling packets

If you haven't already please read High level Multiplayer and as for script Ping Pong is an excellent place to start

Use IP.get_local_addresses()[0] to get the device's ip
The way Android is setup Data takes priority then wifi then localhost and on some devices Bluetooth registers as an interface and takes priority. So make sure all are off except the one you want to use or if you're familiar with Unix peripherals you can use IP.get_local_interfaces() instead and filter by interface name

On the device that creates the server do network_peer.set_bind_ip(MY_DEVICE_IP) before the create_server call and use that as the server for the other peers to connect to

Unlikely that you will need to for a debug build but remember to also enable internet related permissions

by (4,472 points)
selected by

Thank you for give me boost information.

High level multiplayer configure:
IP.getlocaladdresses()[0] its always get local ip 127.0.0.1 in device,
this local ip to create server (host) alway throughout error in device but emulator work.

I know it's return array but which ip used for MYDEVICEIP ??? [how can i identifier ip from array]

also peer.createclient(SERVERIP, SERVER_PORT)
enter SERVER_IP hard code on join time ?

SERVER_IP has to be the address of the device that is hosting and made the call to network_peer.create_server() make sure to use network_peer.set_bind_ip() first on that device

Assuming you're using DHCP, Android device ips are structured this way

127.0.0.1 localhost
192.168.0.1 wlan(wifi)
192.168.53.1 hotspot (wifi)
192.168.53.129 hotspot (usb)
274.69.253.80 Data

So in the list returned by using IP.get_local_addresses() just select the appropriate one

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.