-- Contributed by Don Berryman (berryman@orca.drep.dnd.ca) -- -- This program receives varing length packets sent by -- BROADCASTER over a UDP Datagram Broadcast Socket. -- It is only possible to have ONE RECEIVER per CPU, but -- each CPU on a network can have its own receiver. The -- problem is that the BIND must be to a unique address -- and port number on a particular machine. with text_io; with ERROR, DEBUG, INET, NETWORK, FILE; procedure receiver is package net renames network; package intio is new text_io.integer_io (natural); bufsize: constant integer := 64; subtype buffer is string(1..bufsize); procedure buf_recvfrom is new file.recvfrom (buffer, false); port: constant inet.ipport := 1456; domain: constant net.address_format := net.af_inet; sock: file.descriptor; buf: buffer := (others => ascii.nul); server: file.sockaddr (family => net.af_inet); client: file.sockaddr (family => net.af_inet); rval: natural := 0; begin sock := file.socket (domain, file.dgram); file.sockopt.set_rcvbuf (sock, 16384); server.addr := inet.addr_any; server.port := port; file.bind (sock, server); loop buf_recvfrom (sock, buf, bufsize, file.msg_none, client, rval); text_io.put ("From " & inet.ntoa(client.addr)); text_io.set_col (20); text_io.put (" Bytes:"); intio.put (rval, 3); text_io.put (" <<<" & buf(1..rval) & ">>>"); text_io.new_line; end loop; end receiver;