Socket starts listening after player/bot joins, never on server start.

So the following code is what starts the socket, binds it and starts listening:


function onListen(sock, err)
	if err == GLSOCK_ERROR_SUCCESS then
		sock:Accept(receive)
		print("Listening on port ".. port)
	else
		print("Failed to listen on port ".. port)
	end
end

function init()
	sock = GLSock(GLSOCK_TYPE_ACCEPTOR)
	sock:Bind("", port, function(sock, err)
		if (err == GLSOCK_ERROR_SUCCESS) then
			print("Successfully bound to port ".. port)
			sock:Listen(0, onListen)
		else
			print("Failed to bind to port ".. port)
		end
	end)
end

init()

In my console I get “Successfully bound to port 1234” but no message saying “Listening on port 1234” until after a player/bot joins. A friend helped with spawning a bot and kicking it but the bot is never kicked so I’m looking for an alternative method of doing it.

Any help will be appreciated.

The reason is because the server is in sleep mode until the first player spawns. Basically a timescale of 0 and think isn’t called. I think you could move the socket receive function from Think to Tick and it would work.