C++ Sockets Library
Windows users should download the .zip archive, where all files have the correct end of line characters.
Visual studio project files fails to load if taken from the .tar.gz archive.
This library is available on the
*BSD-Ports system for the Darwin OS.
It is also available through the
FreeBSD Ports Collection.
The library has also been packaged as an rpm package, available from a number of sites. Here are some of them:
Included in the distribution is the sockets_test.cpp, which is a multiple server program with a lot of ports opened.
Port 1024 and 1025 just replies with a text echoing the port number just connected to.
Port 1026 is a small console prompt you can telnet to, and command the program to fetch a web page (command "get http://www.alhem.net/index.html")..
Port 8080 is a HttpDebugSocket server, which will echo back any http request it receives.
188.8.131.52: Multiple fixes in HttpGetSocket, added some missing includes for newer compilers.
184.108.40.206: Fix multiple #include file problems on macosx, win32, and gcc 4.7.
Add support for user/pw in HTTPSocket and Utility url parser.
Switch to clang with environment variable 'USE_CLANG=with_clang'.
Add support for certificate chains in tcp socket.
UdpSocket bugfix, uninitialized variable.
Remove extra namespace 'Xml' from libxml2 wrapper classes.
220.127.116.11: Detach related problems fixed. Detached threads never exited. Pthread attributes was never freed.
Detach from OnAccept did not work, but is now fixed.
18.104.22.168: Sockets-config options added. Fix detach problem. Fix typo in ListenSocket. Please read Changelog.
22.214.171.124: Removed ambigouos operators and constructors. Added missing includes.
Fix memcpy on UdpSocket.
126.96.36.199: Some small fixes (read Changelog for more detail). Added cgi support for HttpRequest / HttpdForm.
Added json support (parse, use, generate).
188.8.131.52: Added multithreaded sockethandler. Semaphore for win32.
Build fixes for mingw/cygwin. Fix sockethandler for win32.
184.108.40.206: Added epoll sockethandler for linux. Fix reconnect (TcpSocket).
220.127.116.11: Major restructure of sockethandler internal code.
Using thread- and memorysafe clib/c runtime functions.
2.3.9: Added limits to http header line length and maximum number of http
headers in http request. Unlimited length header lines can no longer be used
to crash a http server built with the library.
2.3.6: Modified openssl flags to make things flow smoother. Modified license
to allow openssl.
Added unique socket identifier and a new Valid check.
Added filesystem path abstraction methods.
Added Changelog file to distribution, and renamed INSTALL to README.
Added pkgconfig directory and *.pc definition file.
2.3.5: Initialization problems with openssl and win32 fixed.
Added default interface for multicast.
Fix for getnameinfo on macosx (crashed).
Fixed namespace and include problems. Changed to IMutex in one place. Added
IFileUpload interface to HttpdForm but not using it yet.
Fix deadlock in SSLInitializer introduced in 2.3.2.
Added check when select() returns -1 indicating one of the file descriptors
have gone bad. The check rebuilds the fd_set used by select().
Bugfix in HttpGetSocket, one of the constructors had no support in
HttpClientSocket - added.
Corrected bad #include's in Utility.
Added IStream interface to read/write from socket and IFile (memfile, normal
file). New classes SocketStream, FileStream, StreamWriter.
Added ReadInput method in TcpSocket - read from input buffer.
Added GetLine method in TcpSocket - chars input on current line when using
Threadsafe list of ssl initializer, ssl contexts and openssl error text
Added interface for Mutex class, adding the possibility for others to
implement the mutex functionality using other approaches.
Moved FromUtf8 method from XmlNode to Utility.
Request: Remove() method in SocketHandler changed from private to protected.
Added Utility::Stack that returns a stack walk (currently linux only).
Request: Added $(DESTDIR) variable in Makefile for more flexible installation.
The timeout value is now reset before OnTimeout() is called, making it
possible to set a new timeout value in the OnTimeout() method.
2.3: Optimized processing of incoming connections.
Crash bug fix in event handler when deleting event object in
Added Xml wrapper classes (using libxml2).
2.2.9a: Added assignment operator on HttpRequest class.
HttpdForm sometimes got stuck in an infinite loop - fixed.
Lock using const Mutex, and Mutex modified to work when const.
Added Utility::Uri that can be used for parsing of an url.
2.2.9: TcpSocket memory leak found and fixed.
"Lost()" now returns true when a socket has lost connection.
HttpRequest/HttpResponse modified to better cope with multithreaded
2.2.8: MacOS X/Leopard compile issues fix.
Random number generator replaced with a mt implementation.
Utility::Rnd() now return a 32-bit unsigned integer random number.
Http chunked transfer encoding supported.
2.2.7: Http classes no longer makes http request headers lowercase.
HttpRequest query string attribute correctly set.
2.2.6: Work on new http server framework (request, response).
OnDisconnect calls added whenever a connection fails on a read or write operation.
2.2.5: Overflow crash fix in HTTPSocket.
Added separate http_version for HttpResponse. Improved reset of state
information in HTTPSocket and derivates (for keep-alive connections).
MemFile support reads and writes larger than internal blocksize.
2.2.4: UdpSocket timestamp for win32 (faked).
IFile new methods: reset_read and reset_write.
Bugfix in MemFile, a big buffer overflow.
Http Cookies reworked in request/response.
2.2.3: SSL Client/server handshake fixed.
UdpSocket read with timestamp added.
MacOSX xcode project files added.
Build problem on older visual studio fixed.
2.2.2: Lots of small bugfixes.
2.2.1: HTTPSocket fixed. Added exceptions for critical operations (bind, socket).
2.2: HTTPSocket and TcpSocket bug fixes.
More flexible event code.
Added ajp/1.3 support.
2.1.9: Added exception class.
Changed platform selection in Unix Makefile.
Cleaner compile on mingw.
HTTPSocket supports keepalive.
OnDisconnect moved out of ENABLE_RECONNECT scope.
2.1.8: Added missing namespace in SmtpdSocket.
TcpSocket: Calling OnDisconnect when reading 0 bytes.
TcpSocket: Added OnTransferLimit() callback, called when output buffer
size drops below limit set by SetTransferLimit().
Boundary bug (writes over two blocks failed) in MemFile fixed.
Member variables in SSLInitializer no longer static since SSLInitializer
in itself is static in TcpSocket (avoid potential problem with
initialization order of static's).
2.1.7: Bugfix for line protocol mode when reading CRLF across read buffer bounds.
Complete rewrite of tcp output buffers, gaining an OnWriteComplete callback and losing complexity (I hope).
2.1.6: Added general purpose timeout to Socket class (SetTimeout, OnTimeout), and
used it to implement the connection timeout logic in TcpSocket/SctpSocket.
Also added OnConnectTimeout which is called instead of OnTimeout, if the
socket is in Connecting mode.
2.1.5: Socket and IP options reworked. Async DNS cache.
Removed the "distributed framework classes": ICrypt NullCrypt CTcpSocket MinionSocket MinderSocket MinderHandler Uid.
These are still available in v2.1.4 and older.
ListenSocket sets socket option SO_REUSEADDR before calling bind().
Changed default configuration to not use getaddrinfo/getnameinfo for name resolution.
2.1.4: Stability fixes. Added SmtpdSocket.
2.1.3: Mostly SSL updates, like enabling of session resume.
2.1.2: Fix for broken http framework.
Http and httpd tests added.
Configurable options moved to new 'sockets-config.h' file.
2.1.1: Tcp socket Reconnect now works again.
Improved ipv6 support.
Asynchronous resolver now works with ipv6 too.
Safer pointer handling using STL auto_ptr in some cases.
Thread safety improvements, gethostby* functions has been replaced by getnameinfo/getaddrinfo.
2.0.7: SCTP support added.
2.0.6: Optimized SocketHandler, much better performance with many connections (Thanks Samuel).
Using threadsafe dns lookup in unix/linux.
2.0: Timer events, threadsafe operation, optimized SocketHandler,
lots of small bugfixes. Removed redundant ssl classes.
1.9.9: Biggest addition is automatic purging of tcp sockets that would hang around
indefinitely, trying to send all their data. Memleak in TcpSocket fixed.
HttpGetSocket url parse bug fixed. HttpGetSocket binary content buffer fixed.
The rfc1738 decode method fixed. Select() can be called without parameters, meaning
an infinite timeout value.
1.9.8: Mac OS X no longer falsely calls OnConnect.
TcpSocket ssl client now works. Two new callbacks for TcpSocket, when ssl negotiation
fails: OnSSLConnectFailed and OnSSLAcceptFailed.
1.9.7: Lots of small fixes. More care taken to not go over the fd_set limit.
Bugfix protecting the sockethandler from using deleted sockets.
(Socket class destructor calls SocketHandler.Remove in case the socket
is deleted before it is removed from the sockethandler).
Removed a lot of warnings for visual studio .net / 2005 beta.
Fix for bsd sockets sigpipe disable, using SO_NOSIGPIPE.
Solaris use putenv in HttpdSocket.
Added flag flush before close, telling a (tcp) socket to send all data
before closing even while the SetCloseAndDelete flag is set.
Default value: flush before close = true.
Ipv6, documentation, win32 projects, udp. Please see Changelog for
Changed udp sockets to nonblocking.
Documentation and bugfix update. All classes have at least a short description,
and all members in the Socket class also have a short description.
Find the descriptions in the doxygen generated documentation.
Read Changelog for more information.
HttpdSocket http/1.1 keep-alive.
Connection retry / reconnect code improved (it works).
Bugfix for incoming connections.
1.9: Builtin connection retry / reconnect logic.
1.8.6: Better support for write-only socket (stdout).
Check that fd_set limit is never exceeded.
Fix of broken TcpSocket::ReadLine method.
Thread class implemented for win32.
Buffering problem causing large http transfer to drop single bytes fixed.
Added http server framework classes.
Incoming sockets is no longer blocking.
Write (send) too much data no longer causes a disconnect.
SSL support is now integrated in TcpSocket, just like socks4 support.
MacOSX compability issues.
Removed silly warning about read after shutdown.
Removed attempt to close on invalid file descriptor.
ListenSocketBase merged into ListenSocket.
Socks4 client optional functionality added.
HttpGetSocket stores retrieved document in memory.
Optional async DNS functionality added.
New class ListenSocketBase to give sockets more control over how they are
created on incoming connections.
Somewhat experimental shutdown code in Socket::Close added.
New log level: INFO.
New callback on Socket class: OnOptions - use it to set options like
SetReuse and SetKeepalive on your custom socket class.
A few new getters on the MinionSocket class, to support
Applied some of the FreeBSD ports patches.
Cleanup up some signed/unsigned warnings.
Added test projects (sockets_test.cpp) for visual studio 6 and .net.
Added project files and binaries for visual studio .net.
HttpsGetSocket::url_this default port changed to 443 (was 80).
TcpSocket buffer sizes adjusted.
Switched off LineProtocol when reading the http body in HTTPSocket and
1.7.1: CygWin fixes
1.7: Connection pooling added, enabling HTTP/1.1 keep-alive operation.
HttpPostSocket supports both urlencoded and multipart posts.
1.6.4: Socket.GetPort, tutorial updated.
1.6.3: Added new classes: HttpPutSocket, HttpPostSocket and HttpDebugSocket.
Error logging in windows fixed.
1.6.2: Code cleanup. One bugfix in ListenSocket, when opening a random port GetPort() returned
wrong port number - this is now fixed. Removed a lot of #define's for ipv4/ipv6 methods.
Methods are now suffixed with a "6" for the ipv6 variant.
1.6.1: Added dummy copy constructor and assignment operator to classes that couldn't be
copied by default. Many thanks to q for all suggestions and bug squashing!
1.6: Made use of openssl optional.
Win32 compile and link fixes. Bugfixes in buffering, memory leaks fixed,
error logging improved and a general code cleanup. Speed optimizations.
1.5.4: Added small fixes and
multicast functions to UdpSocket after user suggestions and contributions.
1.5.3: Removed resolve of local hostname from SocketHandler constructor.
Replaced read/write in TcpSocket on unix systems to recv/send with flag MSG_NOSIGNAL
to avoid sigpipe.
1.5.2: Added some #ifdef's for those of us unfortunate enough to have an
operating system without IPv6 support.
1.5.1: Updated UDPSocket,
UDP Example (example 9), tutorial updated with udp examples
1.5: C++ Socket library now supports IPv6,
Mac OS X compiles ok, OnConnectFailed callback added
1.4: Added error logging, code cleanup. Tutorial updated with source
1.3.1: Thread support now working a little bit better (Detach() /
Example 7 shows a "small" httpd using the new thread code
- work in progress.
1.3: Tentative pthread support. No win32 threading yet. Also, check out
the new tutorial here.
1.2.2: For all you win32 users out there. I made new visual studio
project files for "Sockets.lib" and "SocketsEx.lib", made sure the code
compiles, and a binary release (1.2.1).
1.2.1: Made a split into two libraries. "libSockets" contains all classes
except Uid, MinionSocket and Minder classes. Those got their own library,
"libSocketsEx", because it's a specialization only used by the minder
application and minion implementations.
1.2: Added minder/minion
framework classes (MinderHandler, MinderSocket,
TcpSocket got a new callback OnRawData() to bypass input buffering.