作为初学者,我想在基于Linux的服务器上使用Lua打开一个Web套接字.此服务器应允许Android客户端连接到它.你能给我一些用Lua打开网络插座的示例代码吗?
两个星期前你已经回答了同样的问题:LUA脚本 - 网络套接字通信.你看过lua-websockets吗?你有什么尝试?什么不起作用?
我之前引用的websockets模块的示例:
-- 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')
Run Code Online (Sandbox Code Playgroud)
你试过吗?遇到问题?
| 归档时间: |
|
| 查看次数: |
7223 次 |
| 最近记录: |