Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const std = @import("std");
- const net = std.net;
- const Address = net.Address;
- pub fn main() !void {
- const address = Address.initIp4(.{ 127, 0, 0, 1 }, 8080);
- var server = try address.listen(.{});
- defer server.deinit();
- var buffer: [1024]u8 = undefined;
- while (true) {
- const connection = server.accept() catch |err| {
- std.debug.print("Error accepting connection: {}", .{err});
- continue;
- };
- const connection_writer = connection.stream.writer(&buffer);
- var writer = connection_writer.interface;
- try writer.print("Hello from Server\n", .{});
- try writer.flush();
- connection.stream.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment