Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Lua脚本语言打开web套接字?_Lua_Websocket - Fatal编程技术网

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

如何使用Lua脚本语言打开web套接字?,lua,websocket,Lua,Websocket,作为初学者,我想在基于Linux的服务器上使用Lua打开一个web套接字。此服务器应允许Android客户端连接到它。您能给我一些使用Lua打开web套接字的示例代码吗?两周前您已经问了同样的问题,答案是:。你看过lua websockets吗?你试过什么?什么不起作用 我先前提到: -- create client: local websocket = require'websocket' local client = websocket.client.copas({timeout=2})

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

两周前您已经问了同样的问题,答案是:。你看过lua 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')

你试过了吗?遇到问题?

这个问题以前在@mrz-yae中被问过,但是有太多的代码,我不知道是哪一个。所以我只想要一个示例代码来打开websocket!这就是全部!谢谢我会试试看,也许以后再问你@JungHur:如果你是一名语言初学者,你还没有准备好做“打开web套接字”之类的复杂事情。@Nicolas感谢你的建议,但我知道使用像你提到的“websocket”这样的东西很有挑战性。但是,出于某些原因,我不得不这么做。我必须实施它。这就是我向这里寻求建议的原因。谢谢你之前的回答,但不是这个。我看过lua websockets。正如你所知(如果你已经检查过的话),有一堆代码。我查看了文件“server_ev”,因为ev安装在我使用的机器中。但是还有很多我不知道的事情。我想要的只是打开websocket和关闭示例代码的几行代码。同样,有人问在哪里买水果,有人回答“在巴黎”,而不是确切的位置。如果你在寻找服务器代码,它就在其中(大部分是注释)。如果你正在寻找客户端,它也在文档中;我在答案中添加了代码片段。谢谢你的回答。正如我所希望的,这个答案对客户来说是完美的答案。但是,我需要的只是服务器端。因为android设备将成为客户端。顺便说一句,事实上,我不认为我用的是“copas”,但“ev”和你的答案是基于copas的。也许它们几乎是一样的。对吗?