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

Nixola
Inner party member
Posts: 1851
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

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

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

Ikroth
Citizen
Posts: 66
Joined: Thu Jul 18, 2013 4:44 am

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

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

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

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

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.

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 ^_^

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

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

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

Nuthen224
Prole
Posts: 46
Joined: Sun Jul 28, 2013 9:40 pm

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

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.

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

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

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!

Who is online

Users browsing this forum: No registered users and 9 guests