LUBE help
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
LUBE help
Hey guys, I don't really understand how LUBE works, can someone please give me a very simple code for a client and a server. A server that simply receives text that the client sends it, that would be incredibly nice. I am so desperate I spent all day trying to understand this...
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: LUBE help
Hi,
I am not a specialist of that networking library, but I can redirect you to that very complete post Technocat did a long time ago on these forums.
See here.
Hope it helps.
Otherwise, you can still give more details on what want to accomplish, and maybe post a *.love showing what you come up with.
I am not a specialist of that networking library, but I can redirect you to that very complete post Technocat did a long time ago on these forums.
See here.
Hope it helps.
Otherwise, you can still give more details on what want to accomplish, and maybe post a *.love showing what you come up with.
Re: LUBE help
I had already seen this thread, but they are all outdated examples, so they don't work with the new love 0.8.0 or the new LUBE. Since I could not find a tutorial, I was hoping for a tiny example just to see how it works, instead of a tutorial you know
Re: LUBE help
This is a basic server
and here is a basic client
To send data back and forth, you'd just use connection:send(data) from either server or client. If you are sending from the server, you can use connection:send(data, clientId) to send to a specific client. Omitting that will send the data to every client.
Don't forget to add connection:update(dt) to your love.update(dt) function or else the callbacks will not fire.
Code: Select all
require "LUBE.LUBE"
port = 12345
connection = lube.tcpServer()
connection.handshake = "handshake"
connection:setPing(true, 6, "ping\n")
connection.callbacks.recv = function(d, id) recv(d, id) end
connection.callbacks.connect = function(id) connect(id) end
connection.callbacks.disconnect = function(id) disconnect(id) end
connection:listen(port)
print('Server started on port: ' .. tostring(port))
--[[
Client Connects to Server
clientId = Unique client ID
]]--
function connect(clientId)
print('Client connected: ' .. tostring(clientId))
end
--[[
Client Disconnects from Server
clientId = Unique client ID
]]--
function disconnect(clientId)
print('Client disconnected: ' .. tostring(clientId))
end
--[[
Receive Data from Client
data = Data received
clientId = Unique client ID
]]--
function recv(data, clientId)
print('Client data received from: ' .. tostring(clientId) .. ' containing: ' .. data)
end
Code: Select all
require "LUBE.LUBE"
host = "localhost"
port = 12345
connection = lube.tcpClient()
connection.handshake = "handshake"
connection:setPing(true, 2, "ping\n")
connection.callbacks.recv = function(d) recv(d) end
if connection:connect(host, port, true) then
print('Connect to ' .. host .. ': ' .. port)
end
--[[
Receive Data from Server
data = Data received
]]--
function recv(data)
print('Server data received: ' .. data)
end
Don't forget to add connection:update(dt) to your love.update(dt) function or else the callbacks will not fire.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
Who is online
Users browsing this forum: slime and 7 guests