added a network boot server compatible with PixICE.
This commit is contained in:
parent
4956591894
commit
bfe7e0276c
27
exec/nbsrv.lua
Normal file
27
exec/nbsrv.lua
Normal file
@ -0,0 +1,27 @@
|
||||
local tA = {...}
|
||||
local nport = tonumber(tA[1])
|
||||
local fpath = tostring(tA[2])
|
||||
for m in component.list("modem") do
|
||||
print("[nbsrv] opening port on "..m)
|
||||
component.invoke(m,"open",nport)
|
||||
end
|
||||
local f=io.open(fpath,"rb")
|
||||
local nbdata = f:read("*a")
|
||||
f:close()
|
||||
spawn("nbsrv: "..tostring(nport)..","..fpath,function()
|
||||
while true do
|
||||
local _, laddress, raddress, port, _, payload = event.pull("modem_message")
|
||||
if port == nport and type(payload) == "string" then
|
||||
if payload:len() == 36 then
|
||||
local sraddress,spayload = raddress:sub(1,8),payload:sub(1,8)
|
||||
print("[nbsrv] request from "..sraddress.."/"..spayload.." on port "..tostring(port))
|
||||
for i = 1, nbdata:len(), 2048 do
|
||||
component.invoke(laddress,"send",raddress,port,nbdata:sub(i,i+2047))
|
||||
end
|
||||
component.invoke(laddress,"send",raddress,port,".")
|
||||
print("[nbsrv] served request from "..sraddress.."/"..spayload)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
print("[nbsrv] nbsrv started.")
|
Loading…
Reference in New Issue
Block a user