LUBE (Networking Library)

Showcase your libraries, tools and other projects that help your fellow love users.
zell2002
Citizen
Posts: 75
Joined: Sun Feb 23, 2014 9:22 pm

Re: LUBE (Networking Library)

Post 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
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LUBE (Networking Library)

Post 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?
zell2002
Citizen
Posts: 75
Joined: Sun Feb 23, 2014 9:22 pm

Re: LUBE (Networking Library)

Post 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
zell2002
Citizen
Posts: 75
Joined: Sun Feb 23, 2014 9:22 pm

Re: LUBE (Networking Library)

Post 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...
Drepic26
Prole
Posts: 1
Joined: Wed Apr 30, 2014 3:41 am

Re: LUBE (Networking Library)

Post by Drepic26 »

Is there a way to stop the server? I searched through the source, but I couldn't find anything.
User avatar
Helvecta
Party member
Posts: 167
Joined: Wed Sep 26, 2012 6:35 pm

Re: LUBE (Networking Library)

Post 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!
"Bump." -CMFIend420
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LUBE (Networking Library)

Post by bartbes »

It does come with a fallback class library, but if a class commons-compatible library is present, it will use that instead.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: LUBE (Networking Library)

Post by jjmafiae »

why classes in lua? lua's strong side is the way of not using object oriented (in my view at least).
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LUBE (Networking Library)

Post 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!
User avatar
whitebear
Citizen
Posts: 86
Joined: Sun Mar 15, 2009 1:50 am

Re: LUBE (Networking Library)

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests