sock.lua - A simple networking library for LÖVE

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Nixola
Inner party member
Posts: 1832
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: sock.lua - A simple networking library for LÖVE

Post by Nixola » Tue Jul 11, 2017 10:36 pm

A thread is "killed" when it returns; that should be enough.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics

User avatar
Ikroth
Citizen
Posts: 64
Joined: Thu Jul 18, 2013 4:44 am

Re: sock.lua - A simple networking library for LÖVE

Post by Ikroth » Tue Jul 11, 2017 10:40 pm

4aiman wrote:
Tue Jul 11, 2017 10:17 pm
Sir_Silver wrote:
Tue Jul 11, 2017 8:01 pm
I believe that, once you've yielded the coroutine...
I'm using love.thread rather than coroutines.
Actually, there's no way to kill a server too - no server:stop() or any other equivalent.
Not sure nilling will do the job and underlying eNet will acknowledge the fact that the nilled server is no more.
So, now there're 2 things I need to be able to kill in reasonable time (of several minutes perhaps?)
You can destroy the server using this function: https://camchenry.com/sock.lua/#Server:destroy

User avatar
4aiman
Party member
Posts: 216
Joined: Sat Jan 16, 2016 10:30 am

Re: sock.lua - A simple networking library for LÖVE

Post by 4aiman » Wed Jul 12, 2017 8:52 am

Nixola wrote:
Tue Jul 11, 2017 10:36 pm
A thread is "killed" when it returns; that should be enough.
Except when an error occurs in a thread. Then it (a thread) seems to not exit at all. I can do thread:getError() as many times as I want till the rest of the lifespan of the main app that has created that thread in the first place.

Ikroth wrote:
Tue Jul 11, 2017 10:40 pm
You can destroy the server using this function: https://camchenry.com/sock.lua/#Server:destroy
Wow! How could I possibly overlook that? Thanks a lot! At least now I can make thread stop via sock's server message. :awesome:


It feels wrong to continue to discuss my threads-related problems here. I've made a different thread here. Please, visit it if you want to help ^_^

User avatar
4aiman
Party member
Posts: 216
Joined: Sat Jan 16, 2016 10:30 am

Re: sock.lua - A simple networking library for LÖVE

Post by 4aiman » Sat Jul 15, 2017 10:39 pm

Is there a way to know the progress of data transmitting?
Say, I'm sending a file of 10Mb.
I need to give some feedback to a client.
Currently it's just a flashing message "Getting updates", but how about a progress bar?

I'm sending data like this:

Code: Select all

client:send("here's your data",binary_data)
I'm fine with sending messages from server like

Code: Select all

client:send("progress",percentage)
, but how is it possible to know the percentage?

Do I have to manually split that binary_data into pieces?


P.S. Sorry for double post, but this post has a different question :neko:

User avatar
Nuthen224
Prole
Posts: 37
Joined: Sun Jul 28, 2013 9:40 pm

Re: sock.lua - A simple networking library for LÖVE

Post by Nuthen224 » Mon Jul 17, 2017 3:13 am

I have some suggestions. Maybe a simpler way would be to just make a guess of how long it will take. You could perhaps calculate a guess based on ping and file size.

If you are sending percentage updates from the server, ensure that is sent over a different channel than the file data or the progress updates wouldn't get sent until after the file is done sending.

Perhaps you could even have the server store the average download time for that file and use that.
Or instead of sending that from the server, instead tell the client the file size in advance and it can calculate the guess.

I don't think there's any need for an exact measurement. Even if you split up the file into pieces and calculated the percent that way, it would fill up the progress bar inconsistently, since the internet is inconsistent. With the way I mentioned, it would increase the percent linearly at least, but it might have finished the file download before it is at 100% if it was an overestimate. Or it would hang at 100% momentarily if it was an underestimate.

User avatar
4aiman
Party member
Posts: 216
Joined: Sat Jan 16, 2016 10:30 am

Re: sock.lua - A simple networking library for LÖVE

Post by 4aiman » Mon Jul 17, 2017 2:05 pm

Uhmm...
I've studied undelying enet lib's articles on the wiki.
It seems threre's no way to send percentage updates, since I can't control how enet splits a huge 20Mb file into tiny packets. Sock counts packets, true, but it calls any message a packet - be it a number or a serialized bunary data of 20+Mb.
On the other hand, sending every file separately increases bandwith (needs measurment) and complexity of a client-server communication. I don't want the latter :)


But I like the idea of estimating.
There's setBandwidth method for a server, I think I can use that to calculate sending time server-side and give that to a client.

Is it worth determining max bandwidth of a hardware connection (presumably using some online service upon server startup) to make my estimates closer to real times, or I can get away with you-run-a-server-so-those-are-your-problems thinking?

Now's the only problem (since threads' behaviour got explained by a number of community members) is the time that server needs to launch yet another thread. Could use some profiling lib, probably.

Thanks, Nuthen224!

Post Reply

Who is online

Users browsing this forum: IsawU and 3 guests