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

C++ Socket library tutorial

New in 2.3: Xml and a new OnDisconnect

Prev   |   Menu   |   Next

v2.3

A new OnDisconnect(flags, code) callback was added alongside the "old" callback without parameters. The "flags" parameter indicates with a bitmap when the disconnect was detected. The TCP_DISCONNECT_WRITE bit is true if the disconnect was detected during a write (send) call, and false if it was disconnected during a read (recv) call. The TCP_DISCONNECT_ERROR is true if the read/write call returned error (-1 normally). It's false if the call returned 0 - zero bytes read, normal indication of a disconnect.. The TCP_DISCONNECT_SSL bit is true if the connection was an ssl connection, and the error code supplied comes from the openssl library. If the TCP_DISCONNECT_SSL bit is false, the error code is "errno" from the read/write call.

There are three new xml classes in this release. XmlDocument, XmlNode, and XmlException. To enable the compilation of these classes the symbol ENABLE_XML must be defined in the sockets-config.h file. By default these classes are turned off, to avoid the additional dependency to libxml2.

XmlDocument
Read an xml document from disk file and perform some checks. The first parameter of the constructor is the xml document filename. The second parameter is the expected namespace, and an xmlexception will be thrown if the namespace in the doesn't match the parameter. The third parameter is the expected top node element name which is also verified with an xmlexception as result if there is a mismatch. The XmlDocument class is used by the XmlNode class to access the root element of the xml document.

XmlNode
The XmlNode class is used to retrieve data from the xml document. Basically the XmlNode is created using the XmlDocument class (search from the root element) or using another XmlNode class (search from the xml element that XmlNode represents). The XmlNode can be used as an iterator to step through all elements on the same level in the xml document. Additionally, an element name can be supplied to only iterate through elements of the same name. The [] operator is used to access child elements by name.

XmlException
XmlException inherits the sockets library Exception class, to simplify try catch construction.

Prev   |   Menu   |   Next

Valid HTML 4.01!

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