标签: luasocket

LuaSocket,Lua 5.2和Redis

有没有人能够让这些合作?我已经5.2工作得很好了,它可以找到lua-redis(redis.lua),但它无法加载套接字模块,我似乎无法使用lua(LuaSocket版本2.0.2).任何人都有任何提示让这个工作?

我已经尝试制作luasocket,但它完全失败,我假设是由于我的lua版本5.2.

答案只是恢复到lua 5.1,还是有另一个我不知道的修复?

c sockets lua luasocket redis

5
推荐指数
1
解决办法
3442
查看次数

使用luasocket和proxy获取url的页面

到目前为止,我有以下内容:

local socket = require "socket.http"
client,r,c,h = socket.request{url = "http://example.com/", proxy="<my proxy and port here>"}
for i,v in pairs( c ) do
  print( i, v )
end
Run Code Online (Sandbox Code Playgroud)

这给了我一个如下输出:

connection  close
content-type    text/html; charset=UTF-8
location    http://www.iana.org/domains/example/
vary    Accept-Encoding
date    Tue, 24 Apr 2012 21:43:19 GMT
last-modified   Wed, 09 Feb 2011 17:13:15 GMT
transfer-encoding   chunked
server  Apache/2.2.3 (CentOS)
Run Code Online (Sandbox Code Playgroud)

这意味着连接建立得非常完美.现在,我想获取url's使用它的标题socket.http.我搜索了以前的SO问题和luasocket的http文档.但是,我仍然不知道如何在变量中获取/存储整个/部分页面并使用它做一些事情.

请帮忙.

sockets lua luasocket fetch

5
推荐指数
1
解决办法
2609
查看次数

如何在Lua中下载文件,但在工作时写入本地文件

我正在尝试创建更新程序,所以当我的Lua应用程序已过期时,它将使用LuaSocket下载较新的.exe文件(可以运行我的Lua代码).

在这个更新程序中,我希望它显示到目前为止已经下载了多少.但是,使用以下HTTP请求,它会阻止应用程序直到完全下载:

local b, c, h = http.request("https://www.example.com/Download/Example.exe?from="..Game.Version)
Run Code Online (Sandbox Code Playgroud)

我正在使用线程下载它,但是在线程内部完成下载之前我仍然无法写入文件,因此进度条将为0%,100%,之间没有任何内容.

我可以做些什么来下载远程文件,但在下载时将其保存到本地文件中?

cURL可以做到这一点.我不知道LuaSocket或Lua的其他任何东西都可以.:(

lua download luasocket

5
推荐指数
1
解决办法
7577
查看次数

是否有与lua 5.2.1兼容的luasocket库?

就像标题所说的那样,我需要一个与Lua 5.2.1兼容的Windows的luasocket库.

sockets windows lua http luasocket

5
推荐指数
1
解决办法
1440
查看次数

我如何处理没有coroutine.yield()的Lua库?

我想下载一个大文件并同时处理其他事情.

但是,luasocket.http从不打电话coroutine.yield().文件下载时,其他所有内容都会冻结.

这是一个说明性示例,我尝试同时下载文件并打印一些数字:

local http = require'socket.http'

local downloadRoutine = coroutine.create(function ()
    print 'Downloading large file'
    -- Download an example file
    local url = 'http://ipv4.download.thinkbroadband.com/5MB.zip'
    local result, status = http.request(url)
    print('FINISHED download ('..status..', '..#result..'bytes)')
end)

local printRoutine = coroutine.create(function ()
    -- Print some numbers
    for i=1,10 do
        print(i)
        coroutine.yield()
    end
    print 'FINISHED printing numbers'
end)

repeat
    local printActive = coroutine.resume(printRoutine)
    local downloadActive = coroutine.resume(downloadRoutine)
until not downloadActive and not printActive
print 'Both done!'
Run Code Online (Sandbox Code Playgroud)

运行它会产生这样的:

1
Downloading …
Run Code Online (Sandbox Code Playgroud)

lua modularity luasocket coroutine

5
推荐指数
1
解决办法
2185
查看次数

在luasocket库中如何检查套接字是否已关闭?

我正在使用Lua编程语言编写服务器,网络层基于LuaSocket.

我在参考手册中找不到任何方法来检测套接字是否已关闭,只是尝试从中读取数据(在调用时它将返回nil和字符串'close').

我的代码看起来像这样:

local socket = require 'socket'
local server = socket.tcp()
local port = 9527

server:bind('*', port)
local status, errorMessage = server:listen()
if status == 1 then
    printf('Server is launched successfully on port %u', port)
else
    printf('Server listen failed, error message is %s', errorMessage)
    return
end

local sockets = {server}

while true do
    local results = socket.select(sockets)
    for _, sock in ipairs(results) do
        if sock == server then
            local s = server:accept()

            callback('Connected', s)
            table.insert(sockets, s)

            printf('%s …
Run Code Online (Sandbox Code Playgroud)

sockets lua tcp luasocket

5
推荐指数
1
解决办法
2508
查看次数

udp 客户端在接收来自服务器的消息时发送 ICMP“端口不可达”

移动:https://superuser.com/questions/782549/udp-client-sending-icmp-port-unreachable-when-receiveing-messages-from-the-ser

我有一个使用 luasocket 的 udp 客户端,基本上是这样做的(有几个抽象层,但这就是那里发生的事情):

s=socket.udp()
s:setsockname("*",0)
s:setpeername(socket.dns.toip("example.com"),64299)
s:settimeout(0)
s:send(...)
s:settimeout(10)
msg,err=s:receive()
s:settimeout(0)
print(msg,err)
Run Code Online (Sandbox Code Playgroud)

虽然在服务器的调试输出中看到一切正常(ssh 到远程主机),但我在客户端中收到“超时”错误。

当使用客户端wireshark检查所有内容时,我看到客户端发送的数据包,以及来自服务器的响应数据包(正确的端口和所有内容),以及从我的客户端主机发送到服务器的ICMP“端口不可达”数据包,以响应这是(正确的)回应。

那里发生了什么事?我尝试了所有方法,包括将 iptables 重置为“接受所有内容”,但我的客户端仍然发送“端口无法访问”。

相关数据包是:

From            To                  Len Description
192.168.2.100   95.143.172.171  UDP 61  Source port: 45025  Destination port: 64299
  000e8f11e7000025229835a908004500002f4008400040112b6fc0a802645f8facabafe1fb2b001b28d794d2000ec8360100aa81a477616e74a3756964
95.143.172.171  192.168.2.100   UDP 60  Source port: 64299  Destination port: 45025
  0025229835a9000e8f11e70008004500002b000040003911727b5f8facabc0a80264fb2bafe100172e8d94d2000e0ea10100a681a3756964ff000000
192.168.2.100   95.143.172.171  ICMP 85 Destination unreachable (Port unreachable)
  000e8f11e7000025229835a9080045c00047061d00004001a492c0a802645f8facab0303cc6c000000004500002b000040003911727b5f8facabc0a80264fb2bafe100172e8d94d2000e0ea10100a681a3756964ff
Run Code Online (Sandbox Code Playgroud)

防火墙,以防万一它很重要(我认为这并不重要,因为 iptables 在发生这种情况时不会增加任何 INPUT 数据包计数器):

$ sudo iptables -S
-P INPUT DROP
-P FORWARD DROP
-P OUTPUT ACCEPT
-A INPUT -i lo …
Run Code Online (Sandbox Code Playgroud)

sockets networking udp luasocket icmp

5
推荐指数
1
解决办法
3万
查看次数

使用 Lua 获取 HTTPS 页面内容

我正在尝试从我的 lua 代码访问网页的内容。以下代码适用于非 HTTPS 页面

local http=require("socket.http")

body,c,l,h = http.request("http://www.example.com:443")

print("status line",l)
print("body",body)
Run Code Online (Sandbox Code Playgroud)

但是在 HTTPS 页面上,我收到以下错误。

您的浏览器发送了此服务器无法理解的请求。
原因:您对启用 SSL 的服务器端口使用纯 HTTP。
请改用 HTTPS 方案访问此 URL。

现在我做了我的研究,有些人建议使用 Luasec,但无论我尝试了多少,我都无法让它工作。此外,Luasec 的库比我正在寻找的要复杂一些。我试图获取的页面仅包含一个 json 对象,如下所示:

{
  "value" : "false",
  "timestamp" : "2017-03-06T14:40:40Z"
}
Run Code Online (Sandbox Code Playgroud)

https lua luasocket luasec

5
推荐指数
2
解决办法
5095
查看次数

Lua socket.http接收器参数

我正在尝试与Lua的服务器通信以验证用户身份.这是我的请求函数的样子:

function http.send(url)
    local req = require("socket.http")
    local b, c, h = req.request{
        url = url,
        redirect = true
    }
    return b
end
Run Code Online (Sandbox Code Playgroud)

但是,我注意到数据被丢弃,因为我没有提供sink参数.我希望能够将下载的数据作为整个字符串返回,而不是下载到文件/表.我该怎么做?

sockets https lua luasocket

4
推荐指数
1
解决办法
2521
查看次数

将luasocket添加到自带lua环境的程序(bizhawk)中

我试图让 luasocket 在Bizhawk的 lua 脚本环境中工作,但到目前为止还没有运气。我在这里下载了vc8版本的luasocket ,确保我已经安装了vc8,并检查了bizhawk自带的lua版本:5.1

但是,当我启动脚本时,出现以下错误:

LuaInterface.LuaScriptException: error loading module 'socket.core' from file './libs/socket\core.dll':
    Das angegebene Modul wurde nicht gefunden. (the given module was not found)
Run Code Online (Sandbox Code Playgroud)

lua代码:

package.path = package.path..';./libs/lua/?.lua'
package.cpath = package.cpath..';./libs/?.dll'
local socket = require("socket")
Run Code Online (Sandbox Code Playgroud)

文件系统结构:

libs
   > lua
       > socket
            ftp.lua http.lua smtp.lua tp.lua url.lua
       ltn12.lua
       mime.lua
       socket.lua
   > socket
       core.dll
   > mime
       core.dll
Run Code Online (Sandbox Code Playgroud)

它似乎找到了文件,因为当我的文件结构错误时,它给了我实际的文件未找到错误。我最好的猜测是,Bizhawk 附带的 lua 和外部 luasocket 库二进制文件之间存在某种不兼容,但我没有想法。

lua luasocket lua-5.1

4
推荐指数
1
解决办法
3040
查看次数

标签 统计

luasocket ×10

lua ×9

sockets ×6

https ×2

c ×1

coroutine ×1

download ×1

fetch ×1

http ×1

icmp ×1

lua-5.1 ×1

luasec ×1

modularity ×1

networking ×1

redis ×1

tcp ×1

udp ×1

windows ×1