IRC client

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
starfruitinc
Posts: 35
Joined: Sat Dec 26, 2009 4:13 am UTC

IRC client

Postby starfruitinc » Sat Oct 01, 2011 7:47 pm UTC

Hello,

I am programming an IRC client, but I have run into a problem. The IRC server does give me any response after I send "JOIN #channel" as a lone packet. The strange thing is, when I send everything at once like this: "NICK lmno \n\rUSER lmno 0 * :lmno\n\rJOIN #mytest\n\r" It works. Can anyone give me some advice for this problem?


Thanks,
SFI
Go FOSS! Rants and discussions on Software and Programming
http://guysonfoss.blogspot.com

A Linux holiday:
http://guysonfoss.blogspot.com/2010/12/special-holiday-episode-and-poem.html

User avatar
zed0
Posts: 179
Joined: Sun Dec 17, 2006 11:00 pm UTC

Re: IRC client

Postby zed0 » Sat Oct 01, 2011 10:54 pm UTC

What about when you send:

Code: Select all

JOIN #channel\n\r

I think you need the end of line in there.

bittyx
Posts: 194
Joined: Tue Sep 25, 2007 9:10 pm UTC
Location: Belgrade, Serbia

Re: IRC client

Postby bittyx » Sun Oct 02, 2011 1:30 am UTC

zed0 is (almost) correct. As per the specs, every command must end in CR-LF - note also that this is "\r\n" and not "\n\r" - while (I assume from your original example), an IRC server will understand the LF-CR ending, it's not defined like that in the specs, so to ensure maximum compatibility, use the correct order (perhaps it's just the server you're testing on that accepts the wrong order). For more on CRLF, read the Wikipedia article.

User avatar
starfruitinc
Posts: 35
Joined: Sat Dec 26, 2009 4:13 am UTC

Re: IRC client

Postby starfruitinc » Sun Oct 02, 2011 2:26 am UTC

Thanks, that was one part of it, it also turns out IRC servers don't like the \0 that is at the ends of c-strings.
Go FOSS! Rants and discussions on Software and Programming
http://guysonfoss.blogspot.com

A Linux holiday:
http://guysonfoss.blogspot.com/2010/12/special-holiday-episode-and-poem.html

User avatar
PM 2Ring
Posts: 3715
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

Re: IRC client

Postby PM 2Ring » Sun Oct 02, 2011 2:51 am UTC

starfruitinc wrote: it also turns out IRC servers don't like the \0 that is at the ends of c-strings.

That shouldn't come as a surprise. :)

Carnildo
Posts: 2023
Joined: Fri Jul 18, 2008 8:43 am UTC

Re: IRC client

Postby Carnildo » Sun Oct 02, 2011 7:57 pm UTC

bittyx wrote:zed0 is (almost) correct. As per the specs, every command must end in CR-LF - note also that this is "\r\n" and not "\n\r" - while (I assume from your original example), an IRC server will understand the LF-CR ending, it's not defined like that in the specs, so to ensure maximum compatibility, use the correct order (perhaps it's just the server you're testing on that accepts the wrong order). For more on CRLF, read the Wikipedia article.

In C, the meaning of the "\n" and "\r" escapes is platform-specific: '\n' is the platform's end-of-line character, while '\r' is the character that '\n' isn't. If you want to be explicit about what's going out on the wire, you need to use the actual ASCII character codes: '\015' for carriage-return and '\012' for linefeed.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 8 guests