Page 33 of 34

Re: LUBE (Networking Library)

Posted: Sun Mar 23, 2014 11:01 am
by zell2002
i havent over ridden them....
-- more code
was me saying, basically, the rest of the function code - i just didnt want to copy it all out - seemed a bit pointless

Re: LUBE (Networking Library)

Posted: Sun Mar 23, 2014 1:04 pm
by bartbes
So the connection callback triggers, but the receive ones never do? Have you tried sending from the client to the server? Do you update the client too?

Re: LUBE (Networking Library)

Posted: Sun Mar 23, 2014 1:28 pm
by zell2002
client calls update(dt) yeah.
and yeah the callbacks are getting called
the recieves get called because they are getting constantly called in the update :

Code: Select all

function udpClient:_receive()
	local data, ip, port = self.socket:receivefrom()
its just this, in the client, always returns : nil, timed out, nil

here is some of the client receive logic
so the first function receive() never gets called
but in the client:update()
if self.callbacks.recv then
local data, err = self:_receive()
this does get called

Code: Select all

function client:receive()
	-- Check if we're connected and pass it on.
	print("client receive")
	if not self.connected then
		return false, "Not connected"
	end
	
	return self:_receive()
end
function client:update(dt)
	if not self.connected then return end
	assert(dt, "Update needs a dt!")
	-- First, let's handle ping messages.
	if self.ping then
		self.ping.timer = self.ping.timer + dt
		if self.ping.timer > self.ping.time then
			self:_send(self.ping.msg)
			self.ping.timer = 0
		end
	end
	-- If a recv callback is set, let's grab
	-- all incoming messages. If not, leave
	-- them in the queue.
        
	if self.callbacks.recv then          
		local data, err = self:_receive()
		while data do
			self.callbacks.recv(data)
			data, err = self:_receive()
		end
	end
end

Re: LUBE (Networking Library)

Posted: Fri Mar 28, 2014 11:41 am
by zell2002
Hi
thought id post back with an example of the server recieving from the client :
server code :

Code: Select all

function onConnect(id)
    server:send("hi", id) -- never gets through
    print(id) -- always prints id
end
function onReceive(data, id)
    print(data .. "sent from "..id) -- always see this
end

function StartServer()
    server = lube.udpServer()
    server:listen("7000")
    server.callbacks.connect = onConnect
    server.callbacks.recv = onReceive
    server.handshake = "Hi!"
    print("started server")
end
client code :

Code: Select all

_ip = "127.0.0.1"
_port = "7000"

function StartClient()
    client = lube.udpClient()
    client.handshake = "Hi!"
    client.callbacks.recv = Receive
    success, er = client:connect(_ip, _port)
    
    print("success : " .. tostring(success)) -- always true, even if the server hasnt been started
    client:send("hello") -- server always receives and prints this (see above)
    return success
end
in LUBE

Code: Select all

function client:update(dt)
	if not self.connected then return end
	assert(dt, "Update needs a dt!")
	-- First, let's handle ping messages.
	if self.ping then
		self.ping.timer = self.ping.timer + dt
		if self.ping.timer > self.ping.time then
			self:_send(self.ping.msg)
			self.ping.timer = 0
		end
	end
	-- If a recv callback is set, let's grab
	-- all incoming messages. If not, leave
	-- them in the queue.
        
	if self.callbacks.recv then
                
		local data, err = self:_receive()
                print(data) -- always nil/false
               print(err) -- "Unknown remote sent data." (from the function udpClient:_receive()
		while data do
			self.callbacks.recv(data)
			data, err = self:_receive()
		end
	end
end
so because data always returns "nil", it never calls my self.callbacks.recv() function

i am really baffled...

Re: LUBE (Networking Library)

Posted: Sat Jun 28, 2014 1:35 am
by Drepic26
Is there a way to stop the server? I searched through the source, but I couldn't find anything.

Re: LUBE (Networking Library)

Posted: Fri Aug 15, 2014 4:52 am
by Helvecta
A library that requires another unincluded library, and class-based at that? Meh, I prefer the old version, but I'm picky. Terrific library!

Re: LUBE (Networking Library)

Posted: Fri Aug 15, 2014 10:20 am
by bartbes
It does come with a fallback class library, but if a class commons-compatible library is present, it will use that instead.

Re: LUBE (Networking Library)

Posted: Fri Aug 15, 2014 7:53 pm
by jjmafiae
why classes in lua? lua's strong side is the way of not using object oriented (in my view at least).

Re: LUBE (Networking Library)

Posted: Sat Aug 16, 2014 8:14 am
by bartbes
jjmafiae wrote:why classes in lua? lua's strong side is the way of not using object oriented (in my view at least).
Because lua is amazing because it allows you to do whatever you want.

With that out of the way, I am using a slightly class-based design for lube these days, but it's mostly because in my opinion objects fit this api well. Don't forget that lua's files mostly act like objects too. And love is object-oriented too!

Re: LUBE (Networking Library)

Posted: Wed Feb 11, 2015 10:35 am
by whitebear
I have trouble getting the client recieve packets from server.
Client to Server = success
Server to Client = fail

my server code: http://hastebin.com/dakiguhegu.lua
my client code: http://hastebin.com/caquvofequ.lua

EDIT got it working with tcp connection but udp still fails on server sending data to user