Advertisement
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 < 2 then
- print("usage : nprint <server address> <file> <v>")
- print(" set 'v' to true for output")
- return false
- end
- local fileName = argv[2]
- local verbose = "false"
- if argv[3] then
- verbose = argv[3]
- 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
- if verbose == "true" then
- print("connection timeout!")
- end
- return false
- end
- if verbose == "true" then
- print("Reading file " .. fileName)
- end
- local data = {}
- local i = 0
- local file = io.open(fileName, "r")
- while true do
- line = file:read()
- if line == nil then
- break
- else
- i = i + 1
- data[i] = line
- end
- end
- file:close()
- if verbose == "true" then
- print("Sending data to ".. argv[1])
- end
- local message ={}
- message["command"] = "print"
- message["filename"] = fileName
- message["data"] = ser.serialize(data)
- message["count"] = i
- network.tcp.send(ch, ser.serialize(message))
- if verbose == "true" then
- print("Closing TCP connection (ch:" .. ch .. ").")
- end
- network.tcp.close(ch)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement