Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ws = require("websocket_client");
- local event = require("event");
- local io = require("io");
- local cl;
- local function save(message)
- local fileName, content = message:match("(%S+) (.+)");
- local file = io.open(fileName, "w");
- file:write(content);
- file:close();
- end
- local function sync(message)
- local fileName = message;
- local file = io.open(fileName);
- local content = "";
- while true do
- if (not file) then break end
- local buffer = file:read(256);
- if (not buffer) then break end
- content = content..buffer;
- end
- cl:send(content);
- file:close();
- end
- local function onMessage(e, msg)
- print("Received Message...");
- local op, message = msg:match("(%S+) (.+)");
- if (op == "sync") then sync(message);
- elseif (op == "save") then save(message) end
- end
- cl = ws.create(onMessage);
- cl:connect("192.168.0.69", 8080, "/", false);
- while true do
- local e = {event.pull()};
- if (e[1] == "interrupted") then break end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement