如何使用Lua脚本语言打开Web套接字? [英] How to open a web socket with Lua scripting language?
本文介绍了如何使用Lua脚本语言打开Web套接字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
作为一个初学者,我想在基于Linux的服务器上使用Lua打开Web套接字.此服务器应允许Android客户端连接到该服务器.您能给我一些用Lua打开Web套接字的示例代码吗?
As a beginner, I want to open a web socket with Lua on a Linux-based server. This server should allow Android client to connect to it. Can you please give me some example code of opening web socket with Lua?
推荐答案
You already asked the same question two weeks ago that was answered: LUA Script - web socket communication. Have you looked at lua-websockets? What have you tried? What's not working?
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')
您尝试过它们吗?遇到问题了?
Have you tried them? Ran into issues?
这篇关于如何使用Lua脚本语言打开Web套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文