You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
955 B
GDScript
36 lines
955 B
GDScript
extends Node
|
|
|
|
const PORT = 8080
|
|
var _server = WebSocketServer.new()
|
|
var peers = [] # everyone currently connected
|
|
|
|
func _ready():
|
|
_server.connect('client_connected', self, "_connected")
|
|
_server.connect('client_disconnected', self, "_disconnected")
|
|
_server.connect('client_close_request', self, "_close_request")
|
|
_server.connect("data_received", self, "_on_data_received")
|
|
|
|
var err = _server.listen(PORT)
|
|
if err != OK:
|
|
print_debug("Unable to start server")
|
|
set_process(false)
|
|
print_debug("server started")
|
|
|
|
func _connected(id, protocol):
|
|
print_debug("Client %d connected with protocol: %s"
|
|
% [id, protocol])
|
|
|
|
func _close_request(id, code, reason):
|
|
print_debug("Client %d disconnecting with code: %d, reason: %s"
|
|
% [id, code, reason])
|
|
|
|
func _disconnected(id, was_clean = false):
|
|
print_debug("Client %d disconnected, clean: %s"
|
|
% [id, str(was_clean)])
|
|
|
|
func _on_data_received(id):
|
|
pass
|
|
|
|
func _process(_delta):
|
|
_server.poll()
|