作为初学者,我想在基于 Linux的服务器上使用Lua打开一个Web套接字.此服务器应允许 Android客户端连接到它.你能给我一些用Lua打开网络插座的示例代码吗? 两个星期前你已经回答了同样的
Examples from the websockets module我之前提到过:
-- 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')
你试过吗?遇到问题?