LUBE help

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
raen79
Citizen
Posts: 55
Joined: Sat Jul 21, 2012 11:58 pm

LUBE help

Post by raen79 »

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...
raen79
Citizen
Posts: 55
Joined: Sat Jul 21, 2012 11:58 pm

Re: LUBE help

Post by raen79 »

Up ? :(
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: LUBE help

Post by Roland_Yonaba »

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.
raen79
Citizen
Posts: 55
Joined: Sat Jul 21, 2012 11:58 pm

Re: LUBE help

Post by raen79 »

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 ;)
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: LUBE help

Post by Karai17 »

This is a basic server

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
and here is a basic client

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
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.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests