Sample code for 30+ languages & platforms
Lua

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 Lua Downloads

Lua
local chilkat = require("chilkat")

local socket = chilkat.Socket.new()

-- Connect to the server using TLS.
local bTls = true
local maxWaitMs = 5000
local success = socket:connect("example.com", 5000, bTls, maxWaitMs)
if not success then
    print(socket.last_error_text)
    return
end

-- 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.
local dupSock = chilkat.Socket.new()
success = socket:dup_socket(dupSock)
if not success then
    print(socket.last_error_text)
    return
end

print("Duplicate socket wrapper created.")