0

这是我第一次在 Lua 中搞乱套接字。无论我尝试什么,我都无法连接。有什么我做错或没有做的吗?

--will store room sockets
Rsock = {}
--will store pm sockets
Psock = {}
--will sore the userlist
userlist = {}
--will store our banned people list
banlist = {}
--threads table only if needed
threads = {}
sock = require "socket";
http = require "socket.http";
local iterate = 0

function getAuth(user, password)
    url = "http://old.yuribot.com/server?inp=get_auth@" 
        .. user .. "-" .. password
    return http.request(url)
end

function getServer(group)
    url = "http://old.yuribot.com/server?inp=group@".. group
    return http.request(url)
end

function room_connect(room)
    sock = sock.tcp();
    host = getServer(room);
    port = 443;
    sock.connect(host, 443);
    Rsock[room] = sock;
    sock:send("bauth:" ..  room  .. ":567765443" .. ":introbot:9911324" .. "\x00");
end

room_connect("shirayuri");
--print(getAuth("introbot", "9911324"));
--print(Rsock['shirayuri'])

PS:网站是shirayuri.chatango.com

4

2 回答 2

0

这对我有用:

local room = 'shirayuri'
local http = require("socket.http")
local body, code = http.request("http://old.yuribot.com/server?inp=group@"..room)
if not body then error(code) end
print(body)

local socket = require("socket")
local conn = socket.tcp()
conn:connect(body, 443)
local res = conn:send("bauth:" ..  room  .. ":567765443" .. ":introbot:9911324")
print(res)

打印“s18.chatango.com”和“42”。

于 2013-09-10T06:13:53.760 回答
0

你遇到了什么错误?我认为问题在于线路 -

sock:connect(host, 443);

它应该是

sock.connect(host, 443);

所以替换 : 与 . 如果您遇到的错误是

bad argument #2 to 'bind' 

如果还有其他错误,请在此处发布。

请参阅http://www.lua.org/pil/16.html了解冒号的作用。

于 2013-09-10T06:12:56.020 回答