Re: sock.lua - A simple networking library for LÖVE
Posted: Tue Jun 27, 2017 4:07 pm
@Ikoroth thank you for reminding me of xpcall. Wondering why didn't I think about this before. LOL! This will solve my problem.
Code: Select all
if current_file_ord and files_to_receive then -- we're getting current_file_ord file out of files_to_receive
if current_file_ord < files_to_receive then -- do we have anything to send?
local rec = sending_list[current_file_ord] -- get a table with info on current file. The table is pre-generated elsewhere
local filename = rec.filename
local prefix = rec.prefix
local file = love.filesystem.newFileData(prefix.."/"..filename) -- get contents of the current file
local hash = md5.sumhexa(file:getString()) -- yet again my thanks to Kikito
sending_to:send("do you need this file?", hash)
end
end
Code: Select all
client:send('I need a file', hash)
Code: Select all
server:on("I need a file", function(data, client) -- remember, that data contains an md5 hash
if not (client_status[client] == 'I need a file') then -- check the status of a client, maybe it had requested that file long ago
client_status[client] = 'I need a file'
local path, type = hashes[data].path, hashes[data].type -- server has all info on hashes pre-generated
local file = love.filesystem.newFileData(path)
client:send("here's your file", file) -- the file
client:send("here's your file", {filename=file:getFilename()}) -- the info on that file
end
end)
Code: Select all
runtime = (runtime or 0) + dt
Code: Select all
love.graphics.print("Uptime:\t".. dt_to_time(runtime),10,30)
So instead of enet chopping your data up, do it yourself? That's +1 thing you need to keep track of, and it doesn't guarantee that enet won't chop it up even more still. It's worth trying though, it's just a bit weird.Nuthen224 wrote: ↑Mon Jul 10, 2017 12:00 am My suggestion is perhaps you could split the file up into smaller segments on your own, perhaps 1kb segments or something, and only send 1kb of data or so per update tick. Keep track of what belongs to what file. If you keep them reliable then they will be received in the correct order. Then assemble them once they are all received, or write to a file as each is received. That could perhaps alleviate this screen freezing by smoothing out the data bottleneck.
I'm using love.thread rather than coroutines.