Can someone give me a server-side code examples, of LuaSocket (like, code that is ran ON the server)?
Thanks!
LuaSocket
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: LuaSocket
Hi !
This is truncated code (no clients or such) but here's a sample of server-side code. It's from an old practice : Github link. Do not hesitate to ask questions if you have so.
This is truncated code (no clients or such) but here's a sample of server-side code. It's from an old practice : Github link. Do not hesitate to ask questions if you have so.
Code: Select all
-- Server Side
-- main.lua
socket = require 'socket'
server = require 'server'
function love.load()
server:start()
end
function love.update(dt)
server:update(dt)
end
function love.draw()
end
Code: Select all
-- Server Side
-- server.lua
local server = {}
clients = require 'clients'
function server:init()
udp = socket.udp()
udp:setsockname(arg[2], arg[3])
udp:settimeout(0)
end
function server:newClient(data, ip, port)
print(data, ip, port)
local client = clients:addClient(ip, port)
udp:sendto(client.id.." "..client.shape._center.x.." "..client.shape._center.y, ip, port)
end
function server:match(data, ip, port)
id, cmd, args = data:match("(%d*) (%a*) (.*)")
if id then
self:responde(id, cmd, args)
end
if tonumber(data) == protocol.magic then
self:newClient(data, ip, port)
end
end
function server:update(dt)
local data, msg_or_ip, port_or_nil = udp:receivefrom()
if not data then return end
if data == "dump" then
clients:dump()
end
self:match(data, msg_or_ip, port_or_nil)
end
return server
- Positive07
- Party member
- Posts: 1014
- Joined: Sun Aug 12, 2012 4:34 pm
- Location: Argentina
Re: LuaSocket
http://w3.impa.br/~diego/software/luaso ... n.html#tcp
http://w3.impa.br/~diego/software/luasocket/tcp.html
https://love2d.org/wiki/socket
https://love2d.org/wiki/Tutorial:Networking_with_UDP If you are using UDP instead of TCP
You should also take a look at ENET
https://love2d.org/wiki/lua-enet
This old post has some server and client example for AN OLDER VERSION of LÖVE (You can still look at the code)
viewtopic.php?f=4&t=8931#p55200
http://w3.impa.br/~diego/software/luasocket/tcp.html
https://love2d.org/wiki/socket
https://love2d.org/wiki/Tutorial:Networking_with_UDP If you are using UDP instead of TCP
You should also take a look at ENET
https://love2d.org/wiki/lua-enet
This old post has some server and client example for AN OLDER VERSION of LÖVE (You can still look at the code)
viewtopic.php?f=4&t=8931#p55200
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Who is online
Users browsing this forum: No registered users and 9 guests