implemented keepalives

This commit is contained in:
Izaya 2018-04-06 16:55:54 +10:00
parent f254ededac
commit 1559364799
2 changed files with 11 additions and 4 deletions

View File

@ -84,9 +84,11 @@ spawn(clientLoop)
function pushLoop()
while true do
for id,msg in pairs(messages) do
for k,client in pairs(clients) do
client.conn:send(msg)
reprint("Message #"..tostring(id).." -> Client #"..tostring(k).." - "..msg)
if msg:len() > 3 then
for k,client in pairs(clients) do
client.conn:send(msg)
reprint("Message #"..tostring(id).." -> Client #"..tostring(k).." - "..msg)
end
end
messages[id] = nil
end

View File

@ -7,6 +7,7 @@ local internet = component.internet
local tArgs = {...}
local addr, raddr = vcomp.uuid(),vcomp.uuid()
local poll, keepalive = tonumber(tArgs[3]) or 5, tonumber(tArgs[4]) or 30
local socket = internet.connect(tArgs[1],tonumber(tArgs[2]))
repeat
@ -16,7 +17,7 @@ until socket.finishConnect()
local proxy = {}
local rbuffer = ""
local timer = event.timer(5,function()
local timer = event.timer(poll,function()
rbuffer=rbuffer..(socket.read(4096) or "")
if imt.decodePacket(rbuffer) then
computer.pushSignal("modem_message",addr,raddr,0,0,imt.decodePacket(rbuffer))
@ -24,6 +25,10 @@ local timer = event.timer(5,function()
end
end,math.huge)
local katimer = event.timer(keepalive,function()
socket.write("\0\1\0")
end,math.huge)
function proxy.send(...)
socket.write(imt.encodePacket(...))
end