Skip to content

Instantly share code, notes, and snippets.

@blainsmith
Created May 9, 2022 16:12
Show Gist options
  • Save blainsmith/cd74a7a1f5623137e71d89e2a7ead64e to your computer and use it in GitHub Desktop.
Save blainsmith/cd74a7a1f5623137e71d89e2a7ead64e to your computer and use it in GitHub Desktop.
UDP Server in Hare
use fmt;
use net::udp;
use net::ip;
use strings;
export fn main() void = {
const listener = udp::listen(ip::LOCAL_V4, 8000)!;
for (true) {
let buf: [1024]u8 = [0...];
let src: ip::addr = ip::ANY_V4;
let port: u16 = 0;
let s = udp::recvfrom(listener, &buf, &src, &port)!;
let buf = buf[..s];
fmt::printfln("{}:{} says {}", ip::string(src), port, strings::fromutf8(buf))!;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment