关于websocket:如何使用Lua脚本语言打开Web套接字?

How to open a web socket with Lua scripting language?

作为一个初学者,我想在基于Linux的服务器上使用Lua打开Web套接字。此服务器应允许Android客户端连接到该服务器。您能给我一些用Lua打开Web套接字的示例代码吗?


您已经在两个星期前问过相同的问题了,该问题已经得到回答:LUA脚本-网络套接字通信。您看过lua-websockets吗?你尝试了什么?什么不起作用?

我先前引用的websockets模块中的示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- 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')

您尝试过吗?遇到问题了吗?