作为初学者,我想在基于 Linux 的服务器上使用 Lua 打开一个 Web 套接字。该服务器应允许 Android 客户端连接到它。你能给我一些用Lua打开网络套接字的示例代码吗?
您两周前已经问过同样的问题并得到了回答:LUA 脚本 - Web 套接字通信 https://stackoverflow.com/questions/16897557/lua-script-web-socket-communication/16901718。你看过lua-websockets吗?你尝试了什么?什么不起作用?
websockets 模块中的示例 https://github.com/lipp/lua-websockets/blob/master/API.md我之前参考过:
-- 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')
你尝试过吗?遇到问题了吗?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)