Zig Requires Chilkat v11.0.0+
Zig
Example: Socket.DupSocket method
See more Socket/SSL/TLS Examples
Demonstrates how to call the DupSocket method.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const socket = try chilkat.Socket.init();
defer socket.deinit();
try socket.connect("example.com", 443, true, 5000);
// ...
// ...
// Duplicate the socket to share the same connection across threads.
// In a multithreaded application, each thread should use its own socket object. For example:
// - The main thread can use the original socket for reading.
// - A secondary thread can use a duplicate for writing.
// - Another thread can use a separate duplicate to monitor the connection status.
const socket_for_sending = try chilkat.Socket.init();
defer socket_for_sending.deinit();
socket.dupSocket(socket_for_sending) catch {
std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
return;
};
const socket_for_monitor = try chilkat.Socket.init();
defer socket_for_monitor.deinit();
socket.dupSocket(socket_for_monitor) catch {
std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
return;
};
// All three socket objects: socket, socket_for_sending, and socket_for_monitor share the same underlying connection.
}