blob: b77c4d5e38942c2eb038201a6d723043b1607184 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
const std = @import("std");
const print = std.debug.print;
const net = std.net;
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();
}
}
|