--------------------------------------------------------- --- TCP library for ZD --------------------------------------------------------- local net = require("net") return function(ZD) ZD.TCPServer = function(port, cb) local tcp = net.createServer(function (client) client:on("data", function(c) cb(client, c) end) end) tcp:listen(port) print("TCP Server listening on port " .. port) return tcp end ZD.TCPClient = function(addr, port, cb) local client = net.createConnection(port, addr, function (err) if err then return print(err) end print("TCP Client connected with " .. addr .." on " .. port) end) client:on("data", function(c) cb(client, c) end) return tcp end end