Page 1 of 2

[Solved] Irc client help

Posted: Mon Dec 30, 2013 2:43 am
by hatninja
I have been trying to make an irc client with love2d as a fun project of mine, and it works... well sorta.
It connects to the irc server absolutely fine, but it receives nothing!

Updated summary of the code:

Code: Select all

local username = "USERNAME"
local nickname = "Username"
local ip = "irc.freenode.net"
local port = "6667"
local channel = "#(ARealWorkingChannel)"
local irc = socket.tcp()

print(irc:connect(ip,tonumber(port)))
irc:settimeout(1)
irc:send("USER "..username.." 8 * :"..username.."\r\n")
irc:send("NICK "..nickname.."\r\n")
irc:send("JOIN "..channel.."\r\n")

--to help get a better understanding of how irc works:
function love.update(dt)
print(irc:receive())
end
Summary of log:

Code: Select all

Running client!
0 timeout
nil timeout
nil closed
nil closed
nil closed
Etc.
I'm dumbfounded as to why it isn't working, please help?

EDIT: Oh, what do you know! changed the port to 8000 and it worked!

Re: Irc client help

Posted: Mon Dec 30, 2013 1:00 pm
by Nixola
Shouldn't the port be 6667?

Re: Irc client help

Posted: Mon Dec 30, 2013 4:06 pm
by hatninja
6697 seems to be the only port that the client can connect to

Re: Irc client help

Posted: Mon Dec 30, 2013 6:45 pm
by Nixola
My IRC bot connects to Freenode through the port 6667, I don't think Freenode accepts connections on other ports
EDIT: Just tested your code, setting the port to 6667 fixes it for me. Also, storing it as string and only using it with tonumber is quite useless, you might want to store it as number directly

Re: Irc client help

Posted: Mon Dec 30, 2013 6:49 pm
by hatninja
Using port 6667 just times it out.
Could i possibly take a look at your irc bot?

Re: Irc client help

Posted: Mon Dec 30, 2013 6:54 pm
by Nixola
Sure! You can find the code here, you'll probably only want to look at main.lua and settings.lua for now

Re: Irc client help

Posted: Mon Dec 30, 2013 7:01 pm
by hatninja
Our code is nearly identical, so i guess something is preventing me from connecting to freenode...
That can't be right at all!

Re: Irc client help

Posted: Mon Dec 30, 2013 7:22 pm
by Nixola
Can you connect using other clients?

Re: Irc client help

Posted: Mon Dec 30, 2013 7:24 pm
by hatninja
Yes, of course.

Re: Irc client help

Posted: Mon Dec 30, 2013 8:13 pm
by Nixola
That's a weird issue then. Can you try to download my bot and see if it works? To run it, you can cd into its directory and run "lua main.lua"; it could work with Love, I think, even if the window would look unresponsive

Edit: I just noticed something, setting the timeout to 0 is a bad idea unless you need nonblocking network operations. If you let LuaSocket wait until it receives a message you'll save a lot of CPU cycles which would go wasted otherwise.