Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local argv = {...}
- local component = require("component")
- local event = require("event")
- local ser = require("serialization")
- local network = require ("network")
- if #argv < 1 then
- print("usage : nptest <server> <v>")
- print("Set v=true for verbose output")
- return false
- end
- local verbose = "false"
- if argv[2] then
- verbose = argv[2]
- end
- if verbose == "true" then
- print("Opening connection to " .. argv[1])
- end
- network.tcp.open(argv[1], 9100)
- local ev, msg, ch, remoteAddr, port = event.pull(3, "tcp") -- 3 seconds time out
- if ev == nil then
- print("connection timeout!")
- return false
- end
- if verbose == "true" then
- print("Sending data to ".. argv[1])
- end
- local message ={}
- message["command"] = "info"
- network.tcp.send(ch, ser.serialize(message))
- ev, type, ch, msg, remoteAddr, port = event.pull(3, "tcp") -- 3 seconds time out
- if ev == nil then
- print("connection timeout!")
- return false
- end
- msgTable = ser.unserialize(msg)
- if msgTable.command == "info" then
- print("Server : " .. remoteAddr)
- print("Version : " .. msgTable.version)
- print("Active jobs : " .. msgTable.jobs)
- print("")
- end
- if verbose == "true" then
- print("Closing TCP connection (ch:" .. ch .. ").")
- end
- network.tcp.close(ch)
Add Comment
Please, Sign In to add comment