LUBE (Networking Library)

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: LUBE (Networking Library)

Post by rude »

I will look into it next time (fist time) I need to use network functions. In particular when I start on Moonfreighter.

Thank you for using the MIT license.
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 »

  • Replaced old files by updated ones.
  • Starting documentation.
  • Finished first version, will be uploaded soon
User avatar
mön
Prole
Posts: 12
Joined: Thu Sep 18, 2008 8:53 am
Location: Zurich
Contact:

Re: LUBE (Networking Library)

Post by mön »

nice! i just tried and managed to connect and send some data :) and i'm confident that this will work much better the tcp server i tried to code some weeks ago. I'm gona use this for a school project which should be done in 10 days... i'll let you know how it worked out.
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 »

I'd like to tell you there is a line of code I forgot in the piece of code that includes the .sock file (both Client and Server)

Code: Select all

elseif love.filesystem.exists(socktype .. ".sock") then
			love.filesystem.require(socktype .. ".sock")
			self[socktype] = _G[socktype]
         *self.socktype = socktype
(I marked the line with a *)
I hope it works out, as I don't want to ruin your school project. ;)
User avatar
mön
Prole
Posts: 12
Joined: Thu Sep 18, 2008 8:53 am
Location: Zurich
Contact:

Re: LUBE (Networking Library)

Post by mön »

hmm, thanks

the servers send function confused me a bit today:

Code: Select all

function server.udp:send(data, rcpt)
	if rcpt then
		return self.socket:sendto(data, rcpt, Clients[rcpt])
	else
		for ip, port in pairs(Clients) do
			return self.socket:sendto(data, ip, port)
		end
	end
end
i expected send to send to every client in the Clients table if rcpt isnt defined, but it returns after it sending to the first client in the list... do you need to return at all?
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

Re: LUBE (Networking Library)

Post by Mr. Strange »

I'm desperate to get my networked game up and running.

Unfortunately, I'm just not at all clear on how to use this to accomplish my goals. I'll lay out exactly what I want from my networking, and maybe you could be kind enough to tell me exactly how to accomplish it.

I have a card game, in which players move cards around a virtual table. There is a database of all of the cards, which each player has locally. Then there is a table which indicates which cards are currently on the table, and where they are located. The draw routine draws the table based upon this information. Every time a card is added, removed, or moved I generate a callback function. I want this function to (among other things) synchronize this table on remote machines running the same application.

I'm not really looking for security, or error-checking. I just want to play go-fish over a network. When I place a card on the virtual playmat, I want my opponent to have their playmat updated to reflect that, by keeping our lua tables synchronized.

Do I need to designate one player the server? How do I connect to my opponents? Is there a limit to the packet size I can send? (That is, will I need to limit the possible # of cards on the playmat?) How can I be relatively certain that our data is synchronized?

--Mr. Strange
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 »

mön wrote:i expected send to send to every client in the Clients table if rcpt isnt defined, but it returns after it sending to the first client in the list... do you need to return at all?
oops... yeah my mistake.. I'll fix that soon


@Mr. Strange
You indeed have to use 1 player as the server (or use a dedicated server somewhere). The maximum package size is the same as that of LuaSocket, which is the same as the UDP standard (if using UDP): 8192 bytes, however you can use multiple packets to synchronize 1 time. To be certain that the data is synchronized, there are 2 methods:
-use TCP
-use "ACK"-packages, in the best case returning an acknowledgement code AND the number of bytes received

A basic implementation would be to send every change a player makes to the server from his/her client, and let the server distribute the new tables. In which case I'd let the server send an ID for one of the tables and send that table in one message, using another for the other table, and maybe another to indicate which player's turn it is.

At the moment I can't answer as good as I want, however, when I'm able to, I will. (yeah, I löve to make confusing sentences)
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

Re: LUBE (Networking Library)

Post by Mr. Strange »

Although your response is clear enough, it doesn't really help me get off the ground. Before I can worry about packet size limitations, I need to actually send an receive a packet.

I really want an example program - something totally simple. For example:

When a player hits a key, display that letter in large type on the screen. When they hit a new key, replace the letter drawn. A second user at a second machine will also see the updated letters.

If someone could provide me with a script that does that, I believe I could start figuring things out from there. Any takers? Any working simple network apps I can peruse? I need a boot-strapping.

--Mr. Strange
User avatar
mön
Prole
Posts: 12
Joined: Thu Sep 18, 2008 8:53 am
Location: Zurich
Contact:

Re: LUBE (Networking Library)

Post by mön »

this might help....
it might also be completly wrong... but it's how i did my first test with lube...
the main.lua in a server.love

Code: Select all

love.filesystem.include("Server.lua")
function load()
  server:Init(1234)--creates an udp server and listens on port 1234
  server:setHandshake("testHS")--sets the handshake
  server:setCallback(reciveCB, connectCB, disconnectCB)--sets the callback functions
end
function update(dt)
  server:update()
end
function draw()
end
function reciveCB(data, ip, port)
  print("recived "..data.." from "..ip)
  server:send("i dont understnad "..data, ip)--sends the data back to where it came from
end
function connectCB(ip, port)
  print("a new client with ip: "..ip.." connected at port: "..port)
end
function disconnectCB(ip, port)
  print("client "..ip.." disconnected)
end
the main.lua in a client.love

Code: Select all

love.filesystem.include("Client.lua")

function load()
  client:Init()
  client:setCallback(networkCB)
  client:setHandshake("testHS")
--[[insert the ip of the machine where the server runs here! you can find the ip by opening a dosbox / commandline and typing ipconfic / ifconfig]]--
  client:connect("***.**.*.***", 1234)
end
function networkCB(data)
  print("the server sais: "..data)
end
function update(dt)
  client:update()
end
function keypressed(key)
  client:send("hello server, how are you today?")
end
User avatar
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

Re: LUBE (Networking Library)

Post by Kuromeku »

"server.lua line 106 attempt to call method receive a nil value".
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 54 guests