Trouble reading a stream to its end
ziggit.dev·4d
🔄epoll
Preview
Report Post

December 23, 2025, 7:16pm 1

Hey everyone! I have been working on a simple TCP read/write example to understand how the new IO worked, and I have been having trouble setting up the reader to simply read till EOF / the end of stream.

Here’s the small example I have (echo.websocket.org is simply an echo server):

const std = @import("std");

const net = std.net;
const print = std.debug.print;

var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();

pub fn main() !void {
const host = "echo.websocket.org";
const stream = try net.tcpConnectToHost(allocator, host, 443);
defer stream.close();

print("Connecting to: {s}\n", .{host});
const data = "hello!";

var buffer: [1024]u8 = undefined;
var stream_reader = stream.reader(&buffer);
var reader = stream_r...

Similar Posts

Loading similar posts...