Idea - Server side code service

Hi All,

I’ve had a thought and just wondered if anyone would have any suggestions?

I’ve started designing a system to execute Lua code on an internet connected server in order to provide multiplayer functionality to games from the community.

I have some ideas for backend functionality but I just wanted to run the initial interface by you all:

function setup()
    
    -- Create Echo server
    local server = Server([==[
        function setup()
            print("Hello World")
        end
    
        -- Called in a loop as fast as possible
        function update()
            
        end
    
        -- Message handler
        function onMessage(msg, client)
            print(msg)
            client:send(msg)
        end
    
        -- Called when a client connects
        function onClientConnected(client)
    
        end
    
        -- Called when a client disconnects
        function onClientDisconnected(client)
    
        end
    ]==], true)
    
    -- Connect to the server
    local client = server:connect()
    
    -- Set message handler
    client.onMessage = function(msg)
        print("Server:", msg)
    end
    
    -- Send a message
    client:send("Ping")
    
    -- Print the server's output log
    print(server:debugLog())
end

Thanks everyone!

Steppers
o7

Looks OK. I’ve been doing something similar with sockets in my robot articles. Calling “as fast as possible” … I’m not sure what that would mean, and one doesn’t want to hot-spin the machine.

@RonJeffries I had debated using that term to be honest as It’ll take some more thought on the backend.

I suspect each ‘server’ running on the backend will be given a time slice and call the update function at roughly 30Hz for consistency.

Yeah 30 or 60 seems fast enough for most purposes at a guess.