Skip to content

Instantly share code, notes, and snippets.

@MEXAHOTABOP
Created July 10, 2018 19:39
Show Gist options
  • Save MEXAHOTABOP/a6934cdb5a01ed8ab10f5777407e0c55 to your computer and use it in GitHub Desktop.
Save MEXAHOTABOP/a6934cdb5a01ed8ab10f5777407e0c55 to your computer and use it in GitHub Desktop.
io = require("io")
event = require("event")
comp = require("component")
wifi = comp.modem
data = comp.data
portStart=15000
portEnd =15100
wifi.open(667)
portIt = 0
--TODO заменить все broadcast на будующую функцию для ретрансляции
while true do
_,_,_,_,_,text,address,filename,md5,compress = event.pull(1,"modem_message")
if text == "check" then
handle,err = io.open(filename)
if handle == nil then
wifi.broadcast(666,"updateserver: cannot open file " .. filename .. " error " .. err)
goto continue
end
md5cur = data.md5(handle:read("*a"))
if md5cur ~= md5 then
if portStart + portIt > portEnd then portIt = 0 end --думаю 100 возможных одновременно запущеных процессов более чем достаточно тем более что я все равно раньше упрусь в память
port = portStart + portIt
wifi.broadcast(667,address,port,md5cur)
os.spawn("/root/sendfile.lua",filename,port,compress)
wifi.broadcast(666,"updateserver: send " .. filename .. " to " .. address .. " via " .. port .. " port", true, port)
portIt = portIt + 1
end
end
::continue::
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment