Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local websocket = require('websocket.client').sync;
- local monitor = peripheral.find("monitor");
- local function printM(string)
- monitor.write(string);
- end
- local ws;
- local function init()
- if ws then
- ws:close();
- ws = nil;
- end
- ws = websocket();
- local ok, err = ws:connect("ws://localhost:8080");
- if not ok then
- print("Connection error: " .. (err or "Unknown error"));
- return;
- end
- print('Connection Opened!');
- end
- init();
- while true do
- local message, err = ws:receive();
- if message then
- printM(message);
- elseif err == "closed" then
- print("Connection Closed");
- ws = nil;
- break;
- else
- print("error" .. err);
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement