From 1559364799b75bfa435283fffe3bf192e4b93b6e Mon Sep 17 00:00:00 2001 From: Izaya Date: Fri, 6 Apr 2018 16:55:54 +1000 Subject: [PATCH] implemented keepalives --- vTunnel/bridge.lua | 8 +++++--- vTunnel/vtunnel.lua | 7 ++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/vTunnel/bridge.lua b/vTunnel/bridge.lua index 5b5ea6b..e355fdb 100644 --- a/vTunnel/bridge.lua +++ b/vTunnel/bridge.lua @@ -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 diff --git a/vTunnel/vtunnel.lua b/vTunnel/vtunnel.lua index 9cd7909..74a06cd 100644 --- a/vTunnel/vtunnel.lua +++ b/vTunnel/vtunnel.lua @@ -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