diff options
author | makefunstuff <[email protected]> | 2024-06-30 19:07:46 +0200 |
---|---|---|
committer | makefunstuff <[email protected]> | 2024-06-30 19:07:46 +0200 |
commit | 058a77eabd6d47e3180360b28b8775a7c19eb064 (patch) | |
tree | fc0a6d287daaadfd69ef507ee3d8d2dcaca681a8 /src/socket-server.zig | |
parent | b6821c1ae54bcb953ef2a7420f6dc89bdc811545 (diff) | |
download | tinkerbunk-058a77eabd6d47e3180360b28b8775a7c19eb064.tar.gz |
naive socket server
Diffstat (limited to 'src/socket-server.zig')
-rw-r--r-- | src/socket-server.zig | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/socket-server.zig b/src/socket-server.zig index 01c5790..b77c4d5 100644 --- a/src/socket-server.zig +++ b/src/socket-server.zig @@ -1,3 +1,22 @@ const std = @import("std"); +const print = std.debug.print; +const net = std.net; -pub fn start_server() !void {} +pub fn start_server() !void { + print("Starting server\n", .{}); + + const ip = [_]u8{ 127, 0, 0, 1 }; + const port = 9000; + + const addr = net.Address.initIp4(ip, port); + + var server = try net.Address.listen(addr, .{}); + print("Listening at {}\n", .{server.listen_address}); + defer server.deinit(); + + while (true) { + var connection = try server.accept(); + _ = try connection.stream.write("Hello, client\n"); + defer connection.stream.close(); + } +} |