Advertisement
Stiepen

KPeriph socket example

May 7th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.48 KB | None | 0 0
  1. local p = peripheral.wrap("side")
  2. local handle p.socket_create("host", port)
  3. p.socket_setAutoFlush(handle, true) -- saves you calling socket_flush(handle) after using socket_write()
  4. p.socket_write(handle, "SomeLine\n")
  5. local e, side, handle2, line = os.pullEvent()
  6. if e == "socket_connectionClosed" and handle == handle2 then
  7.     print("Connection closed")
  8.     return
  9. elseif e == "socket_line" and handle == handle2 then
  10.     print("Line received: "..line)
  11. end
  12. p.socket_close(handle)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement