C++
C++
Duplicate a Socket Wrapper Sharing the Connection
See more Socket/SSL/TLS Examples
Demonstrates Socket.DupSocket, which populates a destination Socket with another wrapper that shares this object's underlying connection.
Background. The shared connection is reference-counted, and all wrappers operate on the same live connection. The destination first releases any connection it previously held.
Chilkat C++ Downloads
#include <CkSocket.h>
void ChilkatSample(void)
{
bool success = false;
CkSocket socket;
// Connect to the server using TLS.
bool bTls = true;
int maxWaitMs = 5000;
success = socket.Connect("example.com",5000,bTls,maxWaitMs);
if (success == false) {
std::cout << socket.lastErrorText() << "\r\n";
return;
}
// Create a second Socket wrapper that shares this object's underlying connection. Both wrappers
// operate on the same live connection; the shared connection is reference-counted.
CkSocket dupSock;
success = socket.DupSocket(dupSock);
if (success == false) {
std::cout << socket.lastErrorText() << "\r\n";
return;
}
std::cout << "Duplicate socket wrapper created." << "\r\n";
}