0 votes

Hi there,

I've recently been trying to learn about how multiplayer works, and started doing some tinkering on my own, so far my file structure looks like this:

.

├── client
│   ├── Client.gd
│   └── Client.tscn
 ...
└── server
    ...
    ├── Server.gd
    └── Server.tscn

Server.gd (note, the only function of interest is processplayerinputs)

extends Node

var peer = NetworkedMultiplayerENet.new()
const PORT = 5000
const MAX_PLAYERS = 500

# Called when the node enters the scene tree for the first time.
func _ready():
    start_server()

func start_server():
    peer.create_server(PORT, MAX_PLAYERS)
    get_tree().set_network_peer(peer)
    print("server started")

    peer.connect("peer_connected", self, "_peer_connected")
    peer.connect("peer_disconnected", self, "_peer_disconnected")

func _peer_connected(player_id):
    print("user " + str(player_id) + " connected")

func _peer_disconnected(player_id):
    print("user " + str(player_id) + " disconnected")

master func process_client_inputs(input):
    print(input)

Client.gd

extends Node

var network = NetworkedMultiplayerENet.new()
const IP_ADDRESS = "127.0.0.1"
const PORT = 5000


# Called when the node enters the scene tree for the first time.
func _ready():
    connect_to_server()

func connect_to_server():
    network.create_client(IP_ADDRESS, PORT)
    get_tree().set_network_peer(network)

    network.connect("connection_succeeded", self, "_connection_succeeded")
    network.connect("connection_failed", self, "_connection_failed")

func _connection_succeeded():
    print("connected to server")

func _connection_failed(player_id):
    print("failed to connect")

func _process(delta):
    rpc_id(1, "process_client_inputs", "got it")

When I run the server, then the client, we get something like this (server left, client right)

client-server-issue-image

Where the first two errors on the client side seem to be rpc requests before the network connection is initialized, and the errors on the server side seem to be coming from the rpc calls from the client.

I've taken a look at the documentation for rpc:

Sends a remote procedure call request for the given method to peers on the network (and locally), optionally sending all additional arguments as arguments to the method called by the RPC. The call request will only be received by nodes with the same NodePath, including the exact same node name. Behaviour depends on the RPC configuration for the given method, see rpcconfig(). Methods are not exposed to RPCs by default. See also rset() and rsetconfig() for properties. Returns null.

After reading this part:

The call request will only be received by nodes with the same NodePath, including the exact same node name.

I know this has to be the issue, the thing is I've been having trouble understanding how to actually fix that up in my specific situation, and to understand the motivation behind why why we would want this to be true.

Hopefully someone can answer these two questions!

Godot version 3.5 Stable
in Engine by (12 points)

Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.