Home  +  Forums  +  C++ and Sockets  +  C++ and SQL: MySQL, sqlite, ODBC  +  Miscellaneous Projects
Logo
~Sockets~
~New~
~Examples~
~Contact~
esta pagina en espanol

C++ Sockets Library

About
This is a GPL licensed C++ class library wrapping the berkeley sockets C API, and therefore works on most unixes and also win32. The library is in use in a number of real world applications, both commercial and open source.

Features include, but are not limited to, SSL support, IPv6 support, tcp and udp sockets, sctp sockets, http protocol, highly customizable error handling. Testing has been done on Linux and Windows 2000, and to some part on Solaris and Mac OS X.

The source code is released under the terms of the GNU GPL, but is also available under an alternative license.

Latest release 2013-06-22: version 2.3.9.9 - download page.

Please see information about how to configure the library.


       
Contributed graphics

History
When making this library, there were a few things I wanted to achieve. I did not want to end up with C++ code that had to be used in the same way as the berkeley socket C API are being used ( connect/bind/accept - check result, write - check result, read - check result, etc, etc ). Another thing was the ability to manage multiple sockets in the same thread; the library should be singlethreaded - but not limited to one thread. So.. I never wanted to manage a fd_set for a select() call ever again, no more writing code for accepting a connection - this has already been done again and again in every single networking project ever made.

One decision made early on was to treat one socket as one object. And so was the Socket class born. The socket class, by itself, has all the functions needed for address translation (hostname to ip, ip to hostname etc). It owns the file descriptor / SOCKET handle. But it can't do anything. Code for actually doing something with the socket is implemented in other, Socket derived classes.

The approach; A list of active sockets are monitored using the select() system call. Events resulting from the select() call and surrounding logic (read/write/connect/timeout etc) are reported to each socket using callback methods such as:

  •   Socket::OnRead()
  •   Socket::OnWrite()
  •   Socket::OnConnect()
  •   Socket::OnAccept()

The list of sockets are contained in a SocketHandler class. To monitor the sockets, repeated calls to the Select() method are made.

Message board

Post bug reports and feature requests here: C++ sockets library message board - If you are using the C++ sockets library, or have any questions about it. To be notified about the latest changes and additions to the C++ sockets library, subscribe to the project at the C++ sockets library freshmeat.net project page.

External open source projects using the library

Links

Page, code, and content Copyright (C) 2021 by Anders Hedström