Advertisement
1lann

Receiver

Feb 6th, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.73 KB | None | 0 0
  1. s = Socket.new("http://chuie.io:9000/", Socket.randomId())
  2.  
  3. s:on("term", function(msg)
  4.   local buffer = textutils.unserialize(msg:gsub("\\u003c", "<"):gsub("\\u003e", ">"):gsub("\\u0026", "&"))
  5.   for k, v in pairs(buffer) do
  6.     local args = v
  7.     local func = args[1]
  8.     table.remove(args, 1)
  9.     term[func](unpack(args))
  10.   end
  11. end)
  12.  
  13. term.clear()
  14. term.setTextColor(colors.white)
  15. term.setCursorPos(1,1)
  16. print("Ready...")
  17.  
  18. local function listener()
  19.     while true do
  20.         local events = {os.pullEvent()}
  21.         if events[1] == "key" or events[1] == "char" or
  22.         events[1] == "mouse_click" or events[1] == "mouse_scroll" then
  23.         s:write("event", textutils.serialize(events):gsub("\n", ""))
  24.         end
  25.     end
  26. end
  27.  
  28. parallel.waitForAny(Socket.run, listener)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement