Created
May 9, 2022 16:12
-
-
Save blainsmith/cd74a7a1f5623137e71d89e2a7ead64e to your computer and use it in GitHub Desktop.
UDP Server in Hare
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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