C++ Class Library for IRC


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

Click here for larger image

Environment: eg VC6, WIN32


This article describes a C++ class library to help programmers implement their own IRC client (like the famous mIRC). The protocols supported by this class library are :


  1. Maintaining a TCP/IP connection to a remote IRC server in a secondary thread.
  2. Identification server (optional. see CIrcSessionInfo).
  3. Full IRC messages two-way parsing.
  4. IRC notifications are posted back to the thread that created the monitor object.
  5. Efficient mechaism of mapping IRC commands to their associated user-defined member functions. This mechanism resembles the way MFC maps Windows(tm) messages to response functions.
  6. Even though the demo project was written using MFC, the library itself was written using only plain C++, STL and WIN32 API.


CIrcMessage (irc.h,irc.cpp) - Parse raw IRC commands into their individual components, and re-build raw commands back from those components.
IIrcSessionMonitor (irc.h,irc.cpp) - Base interface for IRC session monitors.
CIrcSession (irc.h,irc.cpp) - IRC session manager. Maintains a connection to the remote IRC server in a secondary thread, and distributes parsed IRC messages to registered monitors.
CIrcSessionInfo (irc.h,irc.cpp) - IRC connection specs holder.
CIrcMonitor (irc.h,irc.cpp) - Basic session monitor object (derived from IIrcSessionMonitor). This class implements a mechanism that maps IRC commands to user-defined member functions, same as what MFC does with Windows(tm) messages. All notifications are posted outside the context of the connection thread(!)
CIrcDefaultMonitor (irc.h,irc.cpp) - Provides some automatic responses the IRC server requires. (Derived from CIrcMonitor).
CIrcIdentServer (irc.h,irc.cpp) - Identification server. This class is used by the CIrcSession class.


DEFINE_IRC_MAP() (irc.h) - Must be defined inside your CIrcMonitor derived class's definition (.H file).
DECLARE_IRC_MAP(this_class_name, base_class_name) (irc.h) - Must be defined in your CIrcMonitor derived class's implementation file (.CPP).
IRC_MAP_ENTRY(class_name, command, member) (irc.h) - Add entries like this in your class's constructor for each IRC command you'd like to respond to.

Utility Classes

WinsockInit (socket.h,socket.cpp) - Provides automatic winsock initialization. All address resolving code is contained by this class.
Socket (socket.h,socket.cpp) - WIN32 socket's wrapper class.
InetAddr (socket.h,socket.cpp) - Internet address helper class.
CCrossThreadsMessagingDevice (CrossThreadsMessagingDevice.h,CrossThreadsMessagingDevice.cpp) - Used by CIrcMonitor to post IRC notifications back to the thread that the monitor was created in.


  1. The library comes in the form of source-code only (sorry, no DLL yet, although it would certainly make sense to create one), so you just have to add all those source files to your C++ project.
  2. Somewhere inside your project, create an instance of CIrcSession. no derivation needed. This object is your actual connection to the remote IRC server.
  3. To receive notification from the server, you'll have to create a 'monitor' object. This monitor can be any class that is derived from the IIrcSessionMonitor, directory or indirectly. My personal recommendation is to derive from CIrcDefaultMonitor, because it also provides some automatic responses the IRC server requires. (The demo project i provided here is a multiple-document MFC project so there i decided to make the document object as my monitor).
  4. Add the notification handler functions to your monitor object as needed.


Download demo project - 34 Kb
Download source - 9 Kb

Yet to be done

Things I haven't implemented in the current version :

  1. DCC connections (both char and file-transfer).
  2. DLL version.
  3. Unicode support.


  1. RFC #1459 - IRC Protocol
  2. RFC #2812 - IRC Client
  3. RFC #1413 - Identification Protocol
  4. RFC #2813 - IRC Server
  5. Microsoft's MSDN library
  6. "Windows(tm) Sockets Network Programming" by Bob Quinn & Dave Shute, Addison Wesley, ISBN 0-201-63372-8


  • Socket could'nt be created

    Posted by Hati on 07/05/2005 09:34pm

    I imported the six sourcefiles into my MFC ActiveX Project. But when I want to connect, the socket couldn't be created(Class: CIrcSession, Function: Connect), he gives me an error and as a result, there is no connection. What's the matter? Do I have to do something before creating the socket? The Demo-project runs without any problem... Plese help me!

  • ssl

    Posted by Legacy on 11/21/2003 08:00am

    Originally posted by: bill

    has this been updated at all? im just wondering because im trying to implement an ssl connection but having a hard time.

  • Cannot logon to an irc chat

    Posted by Legacy on 07/06/2003 07:00am

    Originally posted by: mega

    I want to logon to irc.nana.co.il
    but I cannot succeed...
    can any one help me?
    rgrds mega

  • problem regarding undeclared identifier

    Posted by Legacy on 06/17/2003 07:00am

    Originally posted by: dave

    Problem Im running into is that on this line of code:

    ASSERT(lpszCmdLine != NULL);

    which comes out of:
    void CIrcMessage::ParseIrcCommand(const char* lpszCmdLine)
    const char* p1 = lpszCmdLine;
    const char* p2 = lpszCmdLine;

    ASSERT(lpszCmdLine != NULL);

    // prefix exists ?
    if( *p1 == ':' )
    { // break prefix into its components (nick!user@host)
    p2 = ++p1;
    while( *p2 && !strchr(" !", *p2) )
    prefix.sNick.assign(p1, p2 - p1);

    gives this error:
    e:\Documents and Settings\Administrator\Desktop\c++ program snippets\irc.cpp(60): error C2065: 'ASSERT' : undeclared identifier

    it keeps complaining about there being an undeclared identifier ... any thoughts?


  • How can i make my own irc server

    Posted by Legacy on 01/28/2003 08:00am

    Originally posted by: Uno tursadi

    How can i make my own irc server?

  • I think that there's a problem when long IRC text...

    Posted by Legacy on 12/29/2002 08:00am

    Originally posted by: Lior

    (like MOTD) is getting cut in the middle, between packets. We get into an infinite loop in CIrcSession::DoReceive(), over the while( *pStart )

    No soultion yet - I'm not sure whther I should fix this or move to MFC socket mechanisms...

  • dragunsflame.am5.com

    Posted by Legacy on 12/27/2002 08:00am

    Originally posted by: dragunsflame

    I got kicked from DALnet for using this thing. Anyone else have the same prob?

  • NEW problem...

    Posted by Legacy on 08/09/2002 07:00am

    Originally posted by: Amir

    I can compile the demo project with no errors,
    but when I try to run it,
    The mainframe is loaded OK,
    But when I choose "File..Open.."
    from the menu of the mainframe,
    when I press the "open" button
    from the toolbar of the mainframe,
    I get a messagebox:
    "Failed to create empty document."
    and nothing else happens.

    Can someone help??


  • the pch file

    Posted by Legacy on 06/05/2002 07:00am

    Originally posted by: Bon


    I just downloaded this and tried to compile it and I got a whole bunch of problems... im not sure i have the right afxdtctl.h file, and i get a error...fatal error C1085: Cannot write precompiled header file: 'Debug/TryIRC2.pch': No space left on device....wht is that..if you could email me that would be great!



    Posted by Legacy on 04/11/2002 07:00am

    Originally posted by: RADIA

    On Win95/98/ME it is Unlikely you shall recieve any data until you fix up the last CreateThread() parameter.

    In IRC.cpp make this change:
    m_hThread = CreateThread(NULL, 0, ThreadProc, this, 0, NULL); // CANNOT HAVE NULL AS LAST PARAMETER ON WINME

    m_hThread = CreateThread(NULL, 0, ThreadProc, this, 0, &dwThreadID);

    You'll need to create a dwThreadID variable:
    DWORD dwThreadID;


  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date