ShialeshD
ShialeshD

Reputation: 1

How to connect two device with live server ip, not a localhost in Godot 3.1?

I a'm using Godot 3.1. Creating two player game, one player own and second player is server(other device player).

Now how to connect two player with live server network?

I a'm creating one demo of two player connect each other and it's working find in local server ip 127.0.0.0 and port 4242.

var SERVER_PORT = 4242
var ip_address  = 127.0.0.1

func join_game(name, ip_address):
   # Initializing the network as server
   var host = NetworkedMultiplayerENet.new()
   host.create_client(ip_address, SERVER_PORT)
   get_tree().set_network_peer(host)

func host_game(name):
   # Initializing the network as client
   var host = NetworkedMultiplayerENet.new()
   host.create_server(SERVER_PORT, 2)
   get_tree().set_network_peer(host)

Above code is proper working in local server but it's ip change our live server it's not working. change 127.0.0.1(localhost ip) to our live server ip address,

Upvotes: 0

Views: 2157

Answers (2)

Walter Wojcik
Walter Wojcik

Reputation: 1

i think you should use "set_bind_ip" when creating the server ...

var peer = NetworkedMultiplayerENet.new()
peer.set_bind_ip( IP_NUMBER ) #### HERE YOU SET THE IP_NUMBER FOR SERVER ...
peer.create_server( SERVER_PORT,1 )

Upvotes: 0

Rahul Rajput
Rahul Rajput

Reputation: 388

There are two option that you want to do, first is internet multiplayer.

For Internet Multiplayer

You have to setup a server in the cloud and create a API. And store the server name and IP address of that server in the database so that you can provide the info the client as the rooms available. so you can Show the users created room's (servers available) in the lobby and give them an option to choose from and now connect with the given server's credential.

Link for creating API and relative tutorial is here

Another possibility is Offline Multiplayer.

Local Multiplayer in LAN

You have basic working multiplayer game now all you have to do is just discover this server across the LAN to do this you can broadcast the server info on all the nodes in the network, and whenever a client is try to search it will receive that info and try to connect to that IP address.

Keep in mind you have to create a new socket for this and run this socket on PORT other than your game.

Search for IP class in Search help box

IP.get_local_addresses() // this will return array of all addresses.
192.168.1.2, 127.0.0.1

Upvotes: 1

Related Questions