Sample code for 30+ languages & platforms
Zig

Send Bytes on a Socket Connection

See more Socket/SSL/TLS Examples

Demonstrates how to send a mixture of binary (non-text) and text bytes on a socket connection.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    const socket = try chilkat.Socket.init();
    defer socket.deinit();

    // Connect to some host:port
    const ssl = false;
    const max_wait_millisec = 20000;
    const port = 5555;
    socket.connect("test.com", port, ssl, max_wait_millisec) catch {
        std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
        return;
    };

    // We wish to send a 0x00 byte followed by the us-ascii string "10800"
    const bd = try chilkat.BinData.init();
    defer bd.deinit();

    bd.appendByte(0) catch {};
    bd.appendString("10800", "utf-8") catch {};

    // Send the entire contents of bd.
    socket.sendBd(bd, 0, 0) catch {
        std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
        return;
    };
}