19.08.2017, 23:32
Hi Admin,
Ok so with a slight modification its now working, see the revised code below. Question in terms of error handling for the connection will this be sufficient for this client script to reconnect if for whatever reason the connection is lost?
Thanks,
Roger
Ok so with a slight modification its now working, see the revised code below. Question in terms of error handling for the connection will this be sufficient for this client script to reconnect if for whatever reason the connection is lost?
Thanks,
Roger
Code:
if not skt then
skt = socket.tcp()
skt:settimeout(5)
skt:connect('192.168.0.11', 2601)
skt, err = ssl.wrap(skt,'tlsv1')
if not err then
skt:dohandshake()
skt = copas.wrap(skt)
copas.addthread(function()
while true do
local resp,err = copas.receive(skt)
-- if theres no connection start a new connection
if not resp or err ~=nil then
alert("[elk-client] Receive error: %s", err)
copas.removeserver(skt)
skt = nil
break
end
if(string.find(resp,'^16XK')==nil)then
local fd,prtd = pcall(parse,resp)
if(fd==false)then
alert("[elk-client] Error with parsemsg %s ",prtd)
end
else
alert('[elk-client] time message: %s', resp)
end
end
end)
else
alert("[elk-client] connection error: %s", err)
skt = nil
return
end
end