#Android not able to host/join games : LAN Peer-to-Peer Multiplayer :

7 messages · Page 1 of 1 (latest)

main dragon
#

Hi there!! It's my first time trying out multiplayer specially in godot aswell as tinkering with Android exports, I need to set up my local multiplayer game into a wireless LAN one as my data gathering for my research subject has been very slow and Im nearing my deadline.

Below is the script I followed from a Godot tutorial "Basics of Multiplayer in Godot" something along those lines. It works perfectly in both Windows PC I was able to connect my gaming laptop with a Win11 OS to my PC with a WIn10 OS, just by using the IP address of the Host PC on both the host address and join/client address over the same wifi router or even a phone wifi hotspot.

PROBLEM: Now Exporting things to android, as you can see I added Debugs on a label, when I either press Host or Join I get this debug messages that I set up that gives me the idea that my Android Game does not have access to the internet, thats what I concluded from 2 observations that I got.

Observation 1: Hosting
Why do I feel that way? Well when I press the hot_game_button I added a print("Host Press") after that Ill call the hostGame() function another print("Waiting for players") should come after as its inside the _hostGame() function. The issue is, it doesn't print "Waiting Players" as if it never created a server.

Observation 2: Joining
Whatever IP address I type on my lobby it always straight up goes for the "couldn't connect" within the connection_failed() function as if it never really tried to reach that IP, it should load for a bit before saying that failed connection similar to what I did back when I was testing my 2 windows PC's there was a second delay before it printed "Player <ID> connected"

#

My Conspiracy:
Im using Godot 4.2 Stable, Im thinking what if its the way I exported the app? I added some permissions like "Wifi States" but it was still the same, i was expecting my phones to ask "Allow this app to access internet" pop up but they never did. Well it is my first time with android. So I get the feeling that my game isnt having access to the internet

#
func _ready():
    multiplayer.peer_connected.connect(peer_connected)
    multiplayer.peer_disconnected.connect(peer_disconnected)
    multiplayer.connected_to_server.connect(connected_to_server)
    multiplayer.connection_failed.connect(connection_failed)


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
    pass

# this get called on the server and clients
func peer_connected(id):
    print("Player Connected " + str(id))
    $Debugger.text = "Player Connected" + " With ID of: " + str(id)
    
# this get called on the server and clients
func peer_disconnected(id):
    print("Player Disconnected " + str(id))
    $Debugger.text = "Player Disconnected"
    

func connected_to_server():
    print("connected To Sever!")
    $Debugger.text = "Connected To Server!"
    SendPlayerInformation.rpc_id(1, $LineEdit.text, multiplayer.get_unique_id())

# called only from clients
func connection_failed():
    $Debugger.text = "Couldnt Connect"
    print("Couldnt Connect")

#

continuation:

func hostGame():
    $Debugger.text = "Processing"
    peer = ENetMultiplayerPeer.new()
    var error = peer.create_server(port, 2)
    if error != OK:
        print("cannot host: " + error)
        $Debugger.text = "cannot host D:"
        return
    peer.get_host().compress(ENetConnection.COMPRESS_RANGE_CODER)
    
    multiplayer.set_multiplayer_peer(peer)
    await get_tree().create_timer(1).timeout
    $Debugger.text = "Waiting For Player"
    print("Waiting For Players!")

@rpc("any_peer")
func SendPlayerInformation(name, id):
    if !GameManager.Players.has(id):
        GameManager.Players[id] ={
            "name" : name,
            "id" : id,
            "score": 0
        }
    
    if multiplayer.is_server():
        for i in GameManager.Players:
            SendPlayerInformation.rpc(GameManager.Players[i].name, i)


func _on_host_button_down():
    hostGame()
    SendPlayerInformation($LineEdit.text, multiplayer.get_unique_id())
    $Debugger.text = "Hosting Pressed"

#join Button
func _on_join_button_down():
    peer = ENetMultiplayerPeer.new()
    peer.create_client(Address, port)
    peer.get_host().compress(ENetConnection.COMPRESS_RANGE_CODER)
    multiplayer.set_multiplayer_peer(peer)
    $Debugger.text = "IP SET TO: " + Address + " WITH PORT: " + str(port)
    print(Address)
    pass # Replace with function body.


func _on_start_button_down():
    startGame.rpc()
    pass # Replace with function body.


func _on_setip_button_down():
    Address = $IPAdress.text
    $Debugger.text = "IP SET TO: " + Address + " WITH PORT: " + str(port)

@rpc("any_peer", "call_local")
func startGame():
    var scene = load("res://WorldTest/TIF_FACILITY.tscn").instantiate()
    get_tree().root.add_child(scene)
    self.hide()
#

Gonna sleep hopefully I get help

#

Android not able to host/join games : LAN Peer-to-Peer Multiplayer :