Well, if you don’t want the user to manually enter the IP, you could just hardcode it, I suppose. Or store the IP somewhere, and then fetch it automatically.
An example in C#:
I did this for now, but without configuring the network, I can’t know before wich IP the server will have. This is why I want to broadcast the server IP when it is setup.
Hey,
I just did a LAN broadcast to do exactly what you need.
So what you need to define on both computers/devices is:
const UDP_BROADCAST_FREQUENCY: float # 3 for me
var udp_network: PacketPeerUDP
var server_broadcasting_udp_port: int # 6868 for me
var _broadcast_timer = 0
then for client, just put in _ready() :
udp_network = PacketPeerUDP.new()
if udp_network.listen(server_broadcasting_udp_port) != OK:
print("Error listening on port: ", server_broadcasting_udp_port)
else:
print("Listening on port: ", server_broadcasting_udp_port)
and in _process(delta):
if udp_network.get_available_packet_count() > 0:
var array_bytes = udp_network.get_packet()
var packet_string = array_bytes.get_string_from_ascii()
var array = packet_string.split(",")
var new_server_id = array[0]
var new_server_name = array[1]
var new_server_port = array[2]
var new_server_players = array[3]
var new_server_max_p = array[4]
# Do want you want with it