Multiplayer and network messaging Server for Godot.
The Godot Client code are in written as class which can be instanced through script.
The main idea of GodotHub is to have a thin server that only handle the connection and broadcast the data to channel(lobby).
GodotHub : GodotHub NodeJS Server
The class for the client is in scripts/godothub.gd . Copy and load it into your game through script.
extends Node
onready var godothub = preload('scripts/godothub.gd')
onready var conn = godothub.new()
func _ready():
set_process(true)
# Connect to message signal of godothub to callback
conn.connect("message",self,"_on_receive")
func _process(dt):
# Listening for packet
conn.is_listening()
# Callback for receiving incoming packet
func _on_receive(data):
print("Receive Data: ",data)
var obj = godothub.new( serverport, serverhost, channel, clientport)
Initialize the godothub object.
serverport
Port of the Server. Default: 5000
serverhost
Host Address of Server. Default: localhost
channel
Initial Lobby or Room. Default: global
clientport
Client's listen port. Default: 4000
obj.is_listening()
Listen for packet.
Return: boolean
obj.change_channel(channel)
Leave current channel and Join new channel. Creating new channel if the channel does not exist yet.
channel
lobby you are changing to.
obj.broadcast(data)
Send data to the server and all clients.
data
The data are formatted into JSON format.
obj.multicast(data)
Send data to the server and all client in current channel.
data
The data are formatted into JSON format.
obj.unicast(data, ID)
Send data to the server and to specified client.
data
The data are formatted into JSON format.
ID
The ID of targeted client.
obj.disconnect_server()
Disconnect from server.
Triggered when connection return error.
Triggered if connection successful.
Triggered when new client joined the channel.
id
is the id of the new client.
Triggered when a client left the channel.
id
is the id of the leaving client.
Triggered when data arrived.
data
The received data.