Teverse makes it easy to create cross-platforn multiplayer experiences with our Lua API. We manage distribution of your apps with our global network of high performance servers.
You should read setting up new apps here.
Download networked.zip - In this example, there is a main.lua script for both the server and client. Note that the server folder is never accessible by clients but the client folder is downloaded to a user's computer.
A client can send a message to the server with one line of code:
-- client teverse.networking:sendToServer("messageName", "Hello World")
We receive this message on the server with the following code:
-- server teverse.networking:on("messageName", function(client, data) print(client.name .. " sent " .. data) end)
With the simple output above, we'd get the following output on the server:
Jay sent Hello World
messageName is the name of the message and you can use any name for your messages. However, do not prefix your message names with an underscore, as this is reserved by our engine and may break your scripts in a future update.
This works the same as client to server communication however there are two additional methods to think about on the server side:
-- server -- Send "Hello World" to everyone subscribed to the "messageName" message teverse.networking:broadcast("messageName", "Hello World")
-- server local client = teverse.networking:getClient("Jay") -- Send "Hello Jay" to Jay if they're subscribed to the "messageName" message teverse.networking:sendToClient(client, "messageName", "Hello World")
A client can subscribe to a message the same way demonstrated above, but note the lack of a client parameter to the callback function.
-- client teverse.networking:on("messageName", function(data) print("The server sent " .. data) end)