You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Place bitser.lua in the same directory as sock.lua.
Require the library and start using it. sock = require 'sock'
* If custom serialization support is needed, look at setSerialization.
Example
localsock=require"sock"-- client.luafunctionlove.load()
-- Creating a new client on localhost:22122client=sock.newClient("localhost", 22122)
-- Creating a client to connect to some ip addressclient=sock.newClient("198.51.100.0", 22122)
-- Called when a connection is made to the serverclient:on("connect", function(data)
print("Client connected to the server.")
end)
-- Called when the client disconnects from the serverclient:on("disconnect", function(data)
print("Client disconnected from the server.")
end)
-- Custom callback, called whenever you send the event from the serverclient:on("hello", function(msg)
print("The server replied: " ..msg)
end)
client:connect()
-- You can send different types of dataclient:send("greeting", "Hello, my name is Inigo Montoya.")
client:send("isShooting", true)
client:send("bulletsLeft", 1)
client:send("position", {
x=465.3,
y=50,
})
endfunctionlove.update(dt)
client:update()
end
-- server.luafunctionlove.load()
-- Creating a server on any IP, port 22122server=sock.newServer("*", 22122)
-- Called when someone connects to the serverserver:on("connect", function(data, client)
-- Send a message back to the connected clientlocalmsg="Hello from the server!"client:send("hello", msg)
end)
endfunctionlove.update(dt)
server:update()
end