Hello there! I want to ask a relatively simple question: how do I find out how many people are currently connected to a local server in DefNet? And also how to send some s-to-c messages without a c-to-s message before that?
britzl
March 28, 2023, 7:49am
2
You can add a new function to the server to return the length of the client table:
assert(port, "You must provide a port")
assert(on_data, "You must provide an on_data function")
log("Creating TCP server")
local server = {}
local co = nil
local server_socket = nil
local clients = {}
local queues = {}
local function remove_client(connection_to_remove)
for i,connection in pairs(clients) do
if connection == connection_to_remove then
table.remove(clients, i)
queues[connection_to_remove] = nil
if on_client_disconnected then
local client_ip, client_port = connection:getpeername()
on_client_disconnected(client_ip, client_port, connection)
1 Like