wrapper java.net.DatagramSocket requiredif RNetwork, RNetAddress, RNetConnection, RNetListener {
requires java.net.SocketHelp;
import naccio.library.NCheck;
import java.net.*;
state RNetAddress local; RNetListener port;
passwrapper <clinit>;
helper void rsetup () {
local = new RNetAddress (getLocalAddress (), getLocalPort ());
port = new RNetListener (local);
RNetwork.openDatagramPort (port);
}
// Don't care about the port number (uses port 0 by default)
wrapper DatagramSocket () {
#;
rsetup ();
}
wrapper DatagramSocket (int port) {
#;
rsetup ();
}
wrapper DatagramSocket (int port, InetAddress laddr) {
#;
rsetup ();
}
// Send/Receive
wrapper void send (DatagramPacket p) {
synchronized (p) {
synchronized (this) {
RNetAddress remote;
remote = new RNetAddress (p.getAddress (), p.getPort ());
RNetwork.preSendDatagram (local, remote, p.getLength ());
#;
RNetwork.postSendDatagram (local, remote, p.getLength ());
}
}
}
wrapper synchronized void receive (DatagramPacket p) {
synchronized (p) {
synchronized (this) {
RNetwork.preReceiveDatagram (local, p.getLength ());
#;
RNetAddress remote;
remote = new RNetAddress (p.getAddress (), p.getPort ());
RNetwork.postReceiveDatagram (local, remote, p.getLength ());
}
}
}
wrapper void close () {
RNetwork.closeDatagramPort (port);
#;
}
}
Naccio Home Page
University of Virginia, Computer Science