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.1 and 2.1.1 and 2.1.3: interface changes

Prev   |   Menu   |   Next

v2.1.3

The InitializeContext() methods on TcpSocket (used for SSL initialization) now has an additional parameter added first in the parameter list, the context name. Each context name will be mapped to one instance of the SSL_CTX struct. The context name is also used as ssl session id.

TcpSocket no longer has a SetRandFile() method. Please see openssl documentation on function call RAND_file_name to make sure the randomness is correctly initialized.

v2.1.1

IpvXAddress classes method GetCopy() now returns a pointer wrapped in the standard librarys auto_ptr template class. The same change has been made for the Socket methods GetClientRemoteAddress and GetRemoteSocketAddress. The Utility::CreateAddress method now also returns an SocketAddress pointer wrapped in the STL auto_ptr.

The Socket class has some new and changed methods for the asynchronous resolver functions.
Resolve6(hostname, port) and OnResolved(id, address, port) has been added for ipv6 support.
For reverse ipv6 lookup there now is a Resolve() method that accepts the in6_addr address structure.
Finally, the OnResolved method returning a reverse resolved hostname has been renamed to OnReverseResolved.

The above changes are also reflected in ISocketHandler, SocketHandler, and ResolvSocket.

New resolve methods in Utility:
u2ip(hostname, ipv6 address structure)
u2ip(hostname, ipv4 address structure)
reverse(ip address structure, hostname)

Ipv6 support is added for win32 and can be enabled in socket_include.h. For windows 2000 the "windows 2000 ipv6 technology preview" has to be installed to use ipv6.

v2.1

SocketHandler now implements ISocketHandler

Version 2.1 is introducing an almost pure virtual base class for the SocketHandler, called ISocketHandler. Because of this, the Socket and StdLog constructors must be changed to accept an "ISocketHandler&" reference instead of "SocketHandler&". The advantage of having a virtual base class for sockethandler is that it is now possible to create really customized handler, optimized for certain tasks. No need to use the almighty do-it-all SocketHandler anymore.

Socket::ReadLine

The Socket::ReadLine callback method has disappeared. If your code was relying on this callback, it's possible to add your own call to the method. This must be added at the end of the OnRead callback method.

void YourSocket::OnRead()
{
	TcpSocket::OnRead();
	if (LineProtocol())
	{
		ReadLine(); // was only called if SetLineProtocol was set true
	}
}

Socket::GetClientRemoteAddress

The methods GetClientRemoteAddr() and GetClientRemotePort() in the Socket class has been replaced by one method returning a SocketAddress pointer. This pointer can be NULL. Here's an example on how to retrieve the remote port used by the client in the OnAccept() method.

void SomeSocket::OnAccept()
{
	SocketAddress *client = GetClientRemoteAddress();
	if (client) // better safe than sorry
	{
		port_t client_port = client -> GetPort();
	}
}
Prev   |   Menu   |   Next

Valid HTML 4.01!

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