加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-14 21:45:36 所属栏目:大数据 来源:网络整理
导读:作为初学者,我想在基于 Linux的服务器上使用Lua打开一个Web套接字.此服务器应允许 Android客户端连接到它.你能给我一些用Lua打开网络插座的示例代码吗? 解决方法 两个星期前你已经回答了同样的问题: LUA Script – web socket communication.你看过lua-web
作为初学者,我想在基于 Linux的服务器上使用Lua打开一个Web套接字.此服务器应允许 Android客户端连接到它.你能给我一些用Lua打开网络插座的示例代码吗?

解决方法

两个星期前你已经回答了同样的问题: LUA Script – web socket communication.你看过lua-websockets吗?你有什么尝试?什么不起作用?

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')

你试过吗?遇到问题?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读