Skip to content

Instantly share code, notes, and snippets.

@haze

haze/tcp.zig Secret

Last active May 5, 2020 21:46
Show Gist options
  • Save haze/211244c6dd14f90961ad3ca71c0fbef4 to your computer and use it in GitHub Desktop.
Save haze/211244c6dd14f90961ad3ca71c0fbef4 to your computer and use it in GitHub Desktop.
(no description)
const std = @import("std");
const net = std.net;
pub const io_mode = .evented;
pub fn main() anyerror!void {
const allocator = &std.heap.ArenaAllocator.init(std.heap.page_allocator).allocator;
const socket = try net.tcpConnectToAddress(try net.Address.parseIp("127.0.0.1", 5000));
const socket_in_stream = socket.inStream();
while (true) {
const bytes = socket_in_stream.readUntilDelimiterAlloc(allocator, '\n', 4096) catch |err| {
switch (err) {
error.EndOfStream => break,
else => return err,
}
};
std.debug.warn("{}\n", .{bytes});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment