"Fossies" - the Fresh Open Source Software Archive

Member "ponyc-0.33.0/examples/net/ping.pony" (1 Nov 2019, 887 Bytes) of package /linux/misc/ponyc-0.33.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Pony source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 use "net"
    2 
    3 class Ping is UDPNotify
    4   let _env: Env
    5   let _ip: NetAddress
    6 
    7   new create(env: Env, ip: NetAddress) =>
    8     _env = env
    9     _ip = ip
   10 
   11   fun ref listening(sock: UDPSocket ref) =>
   12     try
   13       (let host, let service) = sock.local_address().name()?
   14       _env.out.print("Ping: listening on " + host + ":" + service)
   15       sock.write("ping!", _ip)
   16     else
   17       _env.out.print("Ping: couldn't get local name")
   18       sock.dispose()
   19     end
   20 
   21   fun ref not_listening(sock: UDPSocket ref) =>
   22     _env.out.print("Ping: not listening")
   23     sock.dispose()
   24 
   25   fun ref received(sock: UDPSocket ref, data: Array[U8] iso, from: NetAddress)
   26   =>
   27     try
   28       (let host, let service) = from.name()?
   29       _env.out.print("from " + host + ":" + service)
   30     end
   31 
   32     _env.out.print(consume data)
   33     sock.dispose()
   34 
   35   fun ref closed(sock: UDPSocket ref) =>
   36     _env.out.print("Ping: closed")