Search code examples
lualuasocket

Luasocket Telnet Check


I'd like to write a Lua script to run in the background of my server that checks a connection to a server and port every few minutes.

Basically, the logic would go as such:

local success = check_connection("avalon-rpg.com", 443)
if not success then
  os.execute([[kill $(ps aux | grep '[b]ouncer' | awk '{print $2}')]])
  os.execute([[./byoing.sh]])
end

I'm thinking Luasocket will be used to do this, but I'm not sure where to start. Could someone help me with this? It should be a fairly simple project. Thank you :)


Solution

  • You should be able to use local res, err = require('socket').connect("avalon-rpg.com", 443) to do this (you'll get nil, "error message" back if the connection can't be established).

    See connect documentation for details.