I've been trying to make a reliable IRC client for a while now, and I know very little about sockets. I have read the RFC quite a bit, but programmatically responding when appropriate, and detecting errors still boggles me.

How is the program to know the server will send three or four lines before I should send the NICK/USER ?

It seems the only way is to make use of deadline_timers.

I have two failed IRC projects (actually they work, but they aren't good enough to suit me).

One uses boost::ip::tcp::socket's, and the other uses boost::ip::tcp::iostream.

It just seems as if the IRC protocol is a pretty bad one, if it is one at all.

Any tips?

Recommended Answers

All 5 Replies

I've been trying to make a reliable IRC client for a while now, and I know very little about sockets.

Am I the only one who finds this sentence semantically humorous? :D

How is the program to know the server will send three or four lines before I should send the NICK/USER ?

I'm not familiar with the underlying protocols specific to IRC, but have you considered a header packet with necessary bookkeeping information?

I'm now actually fairly certain it isn't a protocol at all, it just has an RFC and a bunch of implementations, I'd guess the server-end is documented more protocol-ish.

To be clear though, I'm trying to automate the entire process instead of having user interaction like knowing when to send the server a username, etc.

Want to see what I mean?
telnet to irc.freenode.org on port 6667 and it'll send a variable number of lines that differ from server to server, then you need to "register"

type "NICK naruekins" [enter]
"USER naruekins 8 * : Anonymous"

then it sends the MOTD and a bunch of other crap. It just isn't a strictly defined protocol, I'd have to wait a certain length of time after connecting to send my nick/user to make sure it reads all the intro BS so that I can receive and parse the error message (if any).

Also, I'm trying to automate the nick/user registration sequence.

I have a suggestion: don't reinvent the wheel. As for my opinion IRC is a past thing:)

Oh heck I like reinventing the wheel.

For the project that uses boost::ip::tcp::iostream, I have a thread that reads lines from the server and a list of "hook" classes that operate on the information line by line.

Anybody else have a magic idea for an implementation?

Well I have one that's working pretty darn good now.

bool ASIO_Internet_Client_TCP::WaitForReadyRead( unsigned int seconds_to_wait )
{
	assert(socket != nullptr);
	unsigned int ms = 0;
	while( !socket->available() )
	{
		boost::asio::io_service ios;
		boost::asio::deadline_timer t(ios, boost::posix_time::milliseconds(10) );
		t.wait();
		ms+=10;
		if( ms > (seconds_to_wait*1000) )
			return false;
	}
	return true;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.