Methods Summary |
---|
protected synchronized void | bind(int lport, java.net.InetAddress laddr)Binds a datagram socket to a local port.
bind0(lport, laddr);
if (laddr.isAnyLocalAddress()) {
anyLocalBoundAddr = laddr;
}
|
protected native synchronized void | bind0(int lport, java.net.InetAddress laddr)
|
protected void | close()Close the socket.
if (fd != null || fd1 != null) {
datagramSocketClose();
fd = null;
fd1 = null;
}
|
protected void | connect(java.net.InetAddress address, int port)Connects a datagram socket to a remote destination. This associates the remote
address with the local socket so that datagrams may only be sent to this destination
and received from this destination.
connect0(address, port);
connectedAddress = address;
connectedPort = port;
connected = true;
|
private native void | connect0(java.net.InetAddress address, int port)
|
protected synchronized void | create()Creates a datagram socket
java.security.AccessController.doPrivileged(
new sun.security.action.LoadLibraryAction("net"));
init();
fd = new FileDescriptor();
fd1 = new FileDescriptor();
datagramSocketCreate();
|
private native void | datagramSocketClose()
|
private native void | datagramSocketCreate()
|
protected void | disconnect()Disconnects a previously connected socket. Does nothing if the socket was
not connected already.
disconnect0(connectedAddress.family);
connected = false;
connectedAddress = null;
connectedPort = -1;
|
private native void | disconnect0(int family)
|
protected void | finalize()
close();
|
public java.lang.Object | getOption(int optID)
if (fd == null && fd1 == null) {
throw new SocketException("Socket Closed");
}
Object result;
switch (optID) {
case SO_TIMEOUT:
result = new Integer(timeout);
break;
case IP_TOS:
result = socketGetOption(optID);
if ( ((Integer)result).intValue() == -1) {
result = new Integer(trafficClass);
}
break;
case SO_BINDADDR:
if (fd != null && fd1 != null) {
return anyLocalBoundAddr;
}
/* fall through */
case IP_MULTICAST_IF:
case IP_MULTICAST_IF2:
case SO_RCVBUF:
case SO_SNDBUF:
case IP_MULTICAST_LOOP:
case SO_REUSEADDR:
case SO_BROADCAST:
result = socketGetOption(optID);
break;
default:
throw new SocketException("invalid option: " + optID);
}
return result;
|
protected native byte | getTTL()Get the TTL (time-to-live) option.
|
protected native int | getTimeToLive()Get the TTL (time-to-live) option.
|
private static native void | init()Perform class load-time initializations.
|
protected void | join(java.net.InetAddress inetaddr)Join the multicast group.
join(inetaddr, null);
|
private native void | join(java.net.InetAddress inetaddr, java.net.NetworkInterface netIf)
|
protected void | joinGroup(java.net.SocketAddress mcastaddr, java.net.NetworkInterface netIf)Join the multicast group.
if (mcastaddr == null || !(mcastaddr instanceof InetSocketAddress))
throw new IllegalArgumentException("Unsupported address type");
join(((InetSocketAddress)mcastaddr).getAddress(), netIf);
|
protected void | leave(java.net.InetAddress inetaddr)Leave the multicast group.
leave(inetaddr, null);
|
private native void | leave(java.net.InetAddress inetaddr, java.net.NetworkInterface netIf)
|
protected void | leaveGroup(java.net.SocketAddress mcastaddr, java.net.NetworkInterface netIf)Leave the multicast group.
if (mcastaddr == null || !(mcastaddr instanceof InetSocketAddress))
throw new IllegalArgumentException("Unsupported address type");
leave(((InetSocketAddress)mcastaddr).getAddress(), netIf);
|
protected native synchronized int | peek(java.net.InetAddress i)Peek at the packet to see who it is from.
|
protected native synchronized int | peekData(java.net.DatagramPacket p)
|
protected synchronized void | receive(java.net.DatagramPacket p)Receive the datagram packet.
try {
receive0(p);
} finally {
fduse = -1;
}
|
protected native synchronized void | receive0(java.net.DatagramPacket p)
|
protected native void | send(java.net.DatagramPacket p)Sends a datagram packet. The packet contains the data and the
destination address to send the packet to.
|
public void | setOption(int optID, java.lang.Object o)set a value - since we only support (setting) binary options
here, o must be a Boolean
if (fd == null && fd1 == null) {
throw new SocketException("Socket Closed");
}
switch (optID) {
/* check type safety b4 going native. These should never
* fail, since only java.Socket* has access to
* PlainSocketImpl.setOption().
*/
case SO_TIMEOUT:
if (o == null || !(o instanceof Integer)) {
throw new SocketException("bad argument for SO_TIMEOUT");
}
int tmp = ((Integer) o).intValue();
if (tmp < 0)
throw new IllegalArgumentException("timeout < 0");
timeout = tmp;
return;
case IP_TOS:
if (o == null || !(o instanceof Integer)) {
throw new SocketException("bad argument for IP_TOS");
}
trafficClass = ((Integer)o).intValue();
break;
case SO_REUSEADDR:
if (o == null || !(o instanceof Boolean)) {
throw new SocketException("bad argument for SO_REUSEADDR");
}
break;
case SO_BROADCAST:
if (o == null || !(o instanceof Boolean)) {
throw new SocketException("bad argument for SO_BROADCAST");
}
break;
case SO_BINDADDR:
throw new SocketException("Cannot re-bind Socket");
case SO_RCVBUF:
case SO_SNDBUF:
if (o == null || !(o instanceof Integer) ||
((Integer)o).intValue() < 0) {
throw new SocketException("bad argument for SO_SNDBUF or " +
"SO_RCVBUF");
}
break;
case IP_MULTICAST_IF:
if (o == null || !(o instanceof InetAddress))
throw new SocketException("bad argument for IP_MULTICAST_IF");
break;
case IP_MULTICAST_IF2:
if (o == null || !(o instanceof NetworkInterface))
throw new SocketException("bad argument for IP_MULTICAST_IF2");
break;
case IP_MULTICAST_LOOP:
if (o == null || !(o instanceof Boolean))
throw new SocketException("bad argument for IP_MULTICAST_LOOP");
break;
default:
throw new SocketException("invalid option: " + optID);
}
socketSetOption(optID, o);
|
protected native void | setTTL(byte ttl)Set the TTL (time-to-live) option.
|
protected native void | setTimeToLive(int ttl)Set the TTL (time-to-live) option.
|
private native java.lang.Object | socketGetOption(int opt)
|
private native void | socketSetOption(int opt, java.lang.Object val)
|