Advertisement
Guest User

tcpecho.lua

a guest
Jan 23rd, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.40 KB | None | 0 0
  1. local c = require("component")
  2. local e = require("event")
  3. local i = c.internet
  4. local a = {...}
  5. local h = a[1]
  6. local p = a[2]
  7. local d = a[3]
  8. local s = i.connect(h, tonumber(p))
  9. while not s:finishConnect() do end
  10. b = s.write(d)
  11. print("TCP_SEND: "..d..", "..b.." bytes")
  12. e.pull("internet_ready")
  13. r = s.read()
  14. print("TCP_RECEIVE: "..r)
  15. if r == d then
  16.   print("Echo success!")
  17. else
  18.   print("Echo.. fail?!")
  19. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement