How to open a web socket with a Lua scripting language?

As a newbie, I want to open a web socket with Lua on a Linux server. This server should allow the Android client to connect to it. Could you give me an example of opening a web socket with Lua?

+4
source share
1 answer

You already asked the same question two weeks ago, to which you were answered: LUA Script - communication via a web socket . Have you looked at lua-websockets? What have you tried? What does not work?

Examples from the websockets module I referenced earlier:

-- create client: local websocket = require'websocket' local client = websocket.client.copas({timeout=2}) -- connect to the server: local ok,err = client:connect('ws://localhost:12345','echo') if not ok then print('could not connect',err) end -- send data: local ok = client:send('hello') if ok then print('msg sent') else print('connection closed') end -- receive data: local message,opcode = client:receive() if message then print('msg',message,opcode) else print('connection closed') end -- close connection: local close_was_clean,close_code,close_reason = client:close(4001,'lost interest') 

Have you tried them? Are you resolving issues?

+7
source

Source: https://habr.com/ru/post/1486576/


All Articles