Sample code for 30+ languages & platforms
Node.js

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 Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

    var socket = new chilkat.Socket();

    //  Connect to the server using TLS.
    var bTls = true;
    var maxWaitMs = 5000;
    success = socket.Connect("example.com",5000,bTls,maxWaitMs);
    if (success == false) {
        console.log(socket.LastErrorText);
        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.
    var dupSock = new chilkat.Socket();
    success = socket.DupSocket(dupSock);
    if (success == false) {
        console.log(socket.LastErrorText);
        return;
    }

    console.log("Duplicate socket wrapper created.");

}

chilkatExample();