summaryrefslogtreecommitdiff
path: root/java/net/MulticastSocket.java
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2002-11-12 07:23:38 +0000
committerMichael Koch <konqueror@gmx.de>2002-11-12 07:23:38 +0000
commit832e6d4ed96aa1c4368fdc9c6bbc0c481810237e (patch)
tree304fc7136e3b241c67e6e672c9e8c4d370078b85 /java/net/MulticastSocket.java
parent81d5a97c4215762f2a555a0824b5eb11a48c4b57 (diff)
downloadclasspath-832e6d4ed96aa1c4368fdc9c6bbc0c481810237e.tar.gz
2002-11-12 Michael Koch <konqueror@gmx.de>
* java/net/NetworkInterface.java: New file. * java/net/DatagramSocketImpl.java (peekData): New method. (joinGroup): New method. (leaveGroup): New method. * java/net/MulticastSocket.java (setNetworkInterface): New method. (getNetworkInterface): New method. (joinGroup): New method. (leaveGroup): New method. * java/net/PlainDatagramSocketImpl.java (peekData): New method. (joinGroup): New method. (leaveGroup): New method. * java/net/PlainSocketImpl.java (connect): New method. (sendUrgentData): New method. (shutdownInput): New method. (shutdownOutput): New method. * java/net/ServerSocket.java (bind): Implemented. * java/net/Socket.java (bind): Implemented. (connect): Implemented. (sendUrgentData): Implemented. (shutdownInput): Implemented. (shutdownOutput): Implemented. * java/net/SocketImpl.java (connect): New method. (sendUrgentData): New method. (shutdownInput): New method. (shutdownOutput): New method.
Diffstat (limited to 'java/net/MulticastSocket.java')
-rw-r--r--java/net/MulticastSocket.java120
1 files changed, 120 insertions, 0 deletions
diff --git a/java/net/MulticastSocket.java b/java/net/MulticastSocket.java
index 820fcc756..3fae77b0e 100644
--- a/java/net/MulticastSocket.java
+++ b/java/net/MulticastSocket.java
@@ -144,6 +144,58 @@ public class MulticastSocket extends DatagramSocket
}
/**
+ * Sets the local network interface used to send multicast messages
+ *
+ * @param netIF The local network interface used to send multicast messages
+ *
+ * @exception SocketException If an error occurs
+ *
+ * @see MulticastSocket:getNetworkInterface
+ *
+ * @since 1.4
+ */
+ public void setNetworkInterface(NetworkInterface netIf)
+ throws SocketException
+ {
+ if (impl == null)
+ throw new SocketException (
+ "MulticastSocket: Cant access socket implementation");
+
+ Enumeration e = netIf.getInetAddresses ();
+
+ if (!e.hasMoreElements ())
+ throw new SocketException ("MulticastSocket: Error");
+
+ InetAddress address = (InetAddress) e.nextElement ();
+ impl.setOption (SocketOptions.IP_MULTICAST_IF, address);
+ }
+
+ /**
+ * Gets the local network interface which is used to send multicast messages
+ *
+ * @return The local network interface to send multicast messages
+ *
+ * @exception SocketException If an error occurs
+ *
+ * @see MulticastSocket:setNetworkInterface
+ *
+ * @since 1.4
+ */
+ public NetworkInterface getNetworkInterface()
+ throws SocketException
+ {
+ if (impl == null)
+ throw new SocketException (
+ "MulticastSocket: Cant access socket implementation");
+
+ InetAddress address =
+ (InetAddress) impl.getOption (SocketOptions.IP_MULTICAST_IF);
+ NetworkInterface netIf = NetworkInterface.getByInetAddress (address);
+
+ return netIf;
+ }
+
+ /**
* Sets the interface to use for multicast packets.
*
* @param addr The new interface to use
@@ -238,6 +290,74 @@ public class MulticastSocket extends DatagramSocket
}
/**
+ * Joins the specified mulitcast group on a specified interface.
+ *
+ * @param mcastaddr The multicast address to join
+ * @param netIf The local network interface to receive the multicast
+ * messages on or null to defer the interface set by #setInterface or
+ * #setNetworkInterface
+ *
+ * @exception IOException If an error occurs
+ * @exception IllegalArgumentException If address type is not supported
+ * @exception SecurityException If a security manager exists and its
+ * checkMulticast method doesn't allow the operation
+ *
+ * @see MulticastSocket:setInterface
+ * @see MulticastSocket:setNetworkInterface
+ *
+ * @since 1.4
+ */
+ public void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf)
+ throws IOException
+ {
+ if (! (mcastaddr instanceof InetSocketAddress))
+ throw new IllegalArgumentException ("SocketAddress type not supported");
+
+ InetSocketAddress tmp = (InetSocketAddress) mcastaddr;
+
+ if (! tmp.getAddress ().isMulticastAddress ())
+ throw new IOException ("Not a Multicast address");
+
+ SecurityManager s = System.getSecurityManager ();
+ if (s != null)
+ s.checkMulticast (tmp.getAddress ());
+
+ impl.joinGroup (mcastaddr, netIf);
+ }
+
+ /**
+ * Leaves the specified mulitcast group on a specified interface.
+ *
+ * @param mcastaddr The multicast address to leave
+ * @param netIf The local networki interface or null to defer to the
+ * interface set by setInterface or setNetworkInterface
+ *
+ * @exception IOException If an error occurs
+ * @exception IllegalArgumentException If address type is not supported
+ * @exception SecurityException If a security manager exists and its
+ * checkMulticast method doesn't allow the operation
+ *
+ * @see MulticastSocket:setInterface
+ * @see MulticastSocket:setNetworkInterface
+ *
+ * @since 1.4
+ */
+ public void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)
+ throws IOException
+ {
+ InetSocketAddress tmp = (InetSocketAddress) mcastaddr;
+
+ if (! tmp.getAddress ().isMulticastAddress ())
+ throw new IOException ("Not a Multicast address");
+
+ SecurityManager s = System.getSecurityManager ();
+ if (s != null)
+ s.checkMulticast (tmp.getAddress ());
+
+ impl.leaveGroup (mcastaddr, netIf);
+ }
+
+ /**
* Sends a packet of data to a multicast address with a TTL that is
* different from the default TTL on this socket. The default TTL for
* the socket is not changed.