54 lines
1.4 KiB
Zig
54 lines
1.4 KiB
Zig
const std = @import("std");
|
|
const transport = @import("crasa-transport");
|
|
const zargs = @import("zargs");
|
|
const log = transport.logging.log;
|
|
|
|
const Config = struct {
|
|
host: []const u8 = "127.0.0.1",
|
|
port: u16 = 9700,
|
|
|
|
pub const meta = .{
|
|
.port = .{
|
|
.short = 'p',
|
|
.help = "UDP port to connect on",
|
|
},
|
|
.host = .{
|
|
.short = 'H',
|
|
.help = "Hostname to resolve",
|
|
},
|
|
};
|
|
};
|
|
|
|
pub fn main() !void {
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
defer _ = gpa.deinit();
|
|
const allocator = gpa.allocator();
|
|
zargs.setAllocator(allocator);
|
|
defer zargs.shutdown();
|
|
|
|
const config: Config = try zargs.parse(Config);
|
|
const argv = try std.process.argsAlloc(allocator);
|
|
defer std.process.argsFree(allocator, argv);
|
|
|
|
if (zargs.isHelp()) {
|
|
const help_text = try zargs.getUsageAlloc("test-client");
|
|
defer allocator.free(help_text);
|
|
std.debug.print("{s}", .{help_text});
|
|
return;
|
|
}
|
|
|
|
log.info("client startup argc={d} port={d}", .{ argv.len, config.port });
|
|
for (argv, 0..) |arg, i| {
|
|
log.info("client argv[{d}]={s}", .{ i, arg });
|
|
}
|
|
|
|
const engine = try transport.UdpEngine.create(allocator);
|
|
defer engine.destroy();
|
|
|
|
try engine.connect(config.host, config.port);
|
|
|
|
while (!engine.shouldExit()) {
|
|
std.Thread.sleep(500 * std.time.ns_per_ms);
|
|
}
|
|
}
|