Sample code for 30+ languages & platforms
Zig

Receive Bytes up to a Delimiter into a BinData

See more Socket/SSL/TLS Examples

Demonstrates Socket.ReceiveUntilByteBd, which reads bytes until a delimiter byte is encountered and appends all bytes up to and including the delimiter to a BinData.

Background. The delimiter is a raw byte value from 0 through 255. This is useful for framing schemes that terminate each message with a known delimiter byte.

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();

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

    // Connect to the server using TLS.
    const b_tls = true;
    const max_wait_ms = 5000;
    socket.connect("example.com", 5000, b_tls, max_wait_ms) catch {
        std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
        return;
    };

    // Read bytes until the delimiter byte is encountered, appending all bytes up to and including the
    // delimiter to a BinData.  The delimiter is a raw byte value from 0 through 255 (here the linefeed
    // byte, decimal 10).
    const bd = try chilkat.BinData.init();
    defer bd.deinit();
    socket.receiveUntilByteBd(10, bd) catch {
        std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Received {d} bytes (including the delimiter).\n", .{bd.getNumBytes()});
}