1

This is my first time messing with sockets in Lua. No matter what I try I can't get it to connect. Is there something I did wrong or did not do?

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

P.S.: the website is shirayuri.chatango.com

Danubian Sailor
  • 1
  • 38
  • 145
  • 223

2 Answers2

1

What error are you getting? I think the issue is with line -

sock:connect(host, 443);

It should be

sock.connect(host, 443);

So replacing : with . should work if the error you are getting is

bad argument #2 to 'bind' 

If there is any other error, do post it here.

refer http://www.lua.org/pil/16.html for what colon does.

robinkc
  • 1,318
  • 8
  • 12
  • I've tried it both ways the sock.connect doesn't error but it won't send the protocol "bauth:room:uid:user:password" and it gives no error –  Sep 10 '13 at 06:16
  • No, the code works as written as he assigns `sock = sock.tcp()`. – Paul Kulchenko Sep 10 '13 at 06:17
  • look here: http://shirayuri.chatango.com/ and then run that and you will see what i mean xD –  Sep 10 '13 at 06:35
0

This works for me:

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)

Prints "s18.chatango.com" and "42".

Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56
  • the function room_connect(room) is suppose to use getServer to get the room server connect to it and send the login information and login that doesn't happen sadly –  Sep 10 '13 at 06:23
  • you don't call getAuth function anywhere in your script. – Paul Kulchenko Sep 10 '13 at 16:27