[SOLVED] LUBE client reception issue

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
Frohman
Prole
Posts: 21
Joined: Sat Dec 08, 2012 12:32 pm

[SOLVED] LUBE client reception issue

Post by Frohman »

Hello yet again, now that I've got LUBE working (due to a bug in hump.class that has since been squashed), I've started to move my plain luasocket processes over to use LUBE, but have hit a snag.

I can set up a server and client (UDP) fine, the server recognises the connection of the client and anything the client sends (which, at the moment, is redirected out the stdout).
The issue is that the client doesn't seem to receive any of the server's messages (both sent via server:send(msg) and server:send(msg, clientid))

Here's the server Lua:

Code: Select all

local Class = require "lib.class"
require "lib.LUBE"
require "player"

port = 8720
universe = {}

local server, numplayers


function love.load()
	print("SERVER BEGIN")

	numplayers = 0
	server = lube.udpServer()
	server.handshake = "space-cowboy"
	server:setPing(true, 15, "ping")
	server:listen(port)
	print("listening on",port)
	server.callbacks.recv = function(d, id) onReceive(d, id) end
	server.callbacks.connect = function(id) onConnect(id) end
	server.callbacks.disconnect = function(id) onDisconnect(id) end
end

function love.update(dt)
	server:update(dt)
end

function onReceive(data, clientid)
	print(clientid, data)
	server:send("HELLO THERE", clientid)
end

function onConnect(clientid)
	print("CON",clientid)
end

function onDisconnect(clientid)
	print("DISCON",clientid)
end
and here's the client Lua:

Code: Select all

local Vector = require "lib.vector"
local Class = require "lib.class"
require "lib.LUBE"
require "player"

local client
-- client = lube.udpClient()

universe = {}
t = 0
tickrate = 5

function love.load()
	love.graphics.setBackgroundColor(33, 89, 125)

	ship = {}
	ship.img = love.graphics.newImage("media/ship.png")
	ship.img:setFilter("linear", "nearest")
	ship.w = ship.img:getWidth()
	ship.h = ship.img:getHeight()

	local cfg = love.filesystem.read("userconfig.cfg")
	local ip, port = cfg:match("^(.+):(%d+)$")
	assert(ip and port)

	client = lube.udpClient()
	client.handshake = "space-cowboy"
	client:setPing(true, 5, "ping")
	client.callbacks.recv = function(d) onReceive(d) end
	assert(client:connect(ip, port, true))
	print(ip, port)
end

function love.update(dt)
	client:update(dt)
	t = t + dt
	if t > tickrate then
		client:send("Hello?")
		print(">Hello?")
		t = t - tickrate
	end
end

function love.draw()
	for k,v in pairs(universe) do
		if v.loaded then
			v:draw(ship)
		end
	end
end

function onReceive(data)
	print(data)
end
(The draw and universe related stuff is not used yet, I'm first trying to get a connection established and functioning in both directions)

If anyone could kindly point out where I'm going wrong with the server/client that might just be causing either the server to not send messages (to the right place?) or the client to not receive them, it'd be much appreciated!

EDIT:
Stay tuned, I think I've solved it.
LUBE needs port as a number (and accepts a string perfectly fine, and will even connect with a string - but won't listen for any messages from the server side, much to my confusion).
Last edited by Frohman on Tue Feb 26, 2013 4:43 pm, edited 1 time in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LUBE client reception issue

Post by bartbes »

Oh, yes, that's probably because the port is passed to luasocket for the actual sending of messages, which is why it probably works sending (I imagine it implicitly converts it, which is kind of bad practice, but whatever), but lube also filters incoming messages, they have to be from the server, of course, so the check there doesn't agree with luasocket's judgment and says "but this numbers is no string!".
Frohman
Prole
Posts: 21
Joined: Sat Dec 08, 2012 12:32 pm

Re: LUBE client reception issue

Post by Frohman »

Yeah, I thought it might be some kind of disagreement between the two layers. Maybe you could throw in an assert that explicitly reinforces this?
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest