Created
June 29, 2020 04:03
-
-
Save anacrolix/73bd4a33becb53e1f303ea24b468d001 to your computer and use it in GitHub Desktop.
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 "net" | |
actor Main | |
new create(env: Env) => | |
let auth = | |
try | |
env.root as AmbientAuth | |
else | |
env.err.print("couldn't get auth") | |
env.exitcode(1) | |
return | |
end | |
Test(env, auth) | |
actor Test | |
let _env: Env | |
let _sock: UDPSocket | |
new create(env: Env, auth: AmbientAuth) => | |
_env = env | |
_sock = UDPSocket( | |
auth, | |
recover MyUDPNotify(this~print_net_address()) end | |
where host="::") | |
be print_net_address(event: String, na: NetAddress) => | |
_env.out.print("got event " + event + " and " + | |
try | |
(let host, let service) = na.name()? | |
"address " + host + ":" + service | |
else | |
"an error from the address name" | |
end | |
) | |
close_socket() | |
be close_socket() => | |
_sock.dispose() | |
type MyUDPNotifyCallback is {(String, NetAddress)} | |
class MyUDPNotify | |
let callback: MyUDPNotifyCallback | |
new create(callback': MyUDPNotifyCallback) => | |
callback = callback' | |
fun not_listening(sock: UDPSocket ref) => | |
callback("not_listening", sock.local_address()) | |
fun listening(sock: UDPSocket ref) => | |
callback("listening", sock.local_address()) | |
fun received(sock: UDPSocket ref, _: Array[U8], _: NetAddress) => | |
callback("received", sock.local_address()) | |
fun closed(sock: UDPSocket ref) => | |
callback("closed", sock.local_address()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment