- Timestamp:
- Apr 27, 2004, 8:39:34 PM (22 years ago)
- Location:
- branches/GNU/src/gcc
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
libjava/java/net/MulticastSocket.java (modified) (12 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gcc
- Property svn:ignore
-
old new 26 26 configure.vr 27 27 configure.vrs 28 28 29 Makefile 29 dir.info30 30 lost+found 31 31 update.out
-
- Property svn:ignore
-
branches/GNU/src/gcc/libjava/java/net/MulticastSocket.java
-
Property cvs2svn:cvs-rev
changed from
1.1to1.1.1.2
r1390 r1391 1 1 /* MulticastSocket.java -- Class for using multicast sockets 2 Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. 2 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 3 Free Software Foundation, Inc. 3 4 4 5 This file is part of GNU Classpath. … … 39 40 40 41 import java.io.IOException; 41 42 /* 42 import java.util.Enumeration; 43 44 /** 43 45 * Written using on-line Java Platform 1.2 API Specification, as well 44 46 * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). … … 47 49 48 50 /** 49 * This class models a multicast UDP socket. A multicast address is a 50 * class D internet address (one whose most significant bits are 1110). 51 * A multicast group consists of a multicast address and a well known 52 * port number. All members of the group listening on that address and 53 * port will receive all the broadcasts to the group. 54 * <p> 55 * Please note that applets are not allowed to use multicast sockets 56 * 57 * Written using on-line Java Platform 1.2 API Specification, as well 58 * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). 59 * Status: Believed complete and correct. 60 * 61 * @author Warren Levy <[email protected]> 62 * @author Aaron M. Renn ([email protected]) (Documentation comments) 63 * @date May 18, 1999. 64 */ 51 * This class models a multicast UDP socket. A multicast address is a 52 * class D internet address (one whose most significant bits are 1110). 53 * A multicast group consists of a multicast address and a well known 54 * port number. All members of the group listening on that address and 55 * port will receive all the broadcasts to the group. 56 * <p> 57 * Please note that applets are not allowed to use multicast sockets 58 * 59 * Written using on-line Java Platform 1.2 API Specification, as well 60 * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). 61 * Status: Believed complete and correct. 62 * 63 * @author Warren Levy <[email protected]> 64 * @author Aaron M. Renn ([email protected]) (Documentation comments) 65 * @since 1.1 66 * @date May 18, 1999. 67 */ 65 68 public class MulticastSocket extends DatagramSocket 66 69 { … … 69 72 // See p.1159 JCL book. 70 73 71 /** 72 * Create a MulticastSocket that this not bound to any address 73 * 74 * @exception IOException If an error occurs 75 */ 74 /** 75 * Create a MulticastSocket that this not bound to any address 76 * 77 * @exception IOException If an error occurs 78 * @exception SecurityException If a security manager exists and its 79 * checkListen method doesn't allow the operation 80 */ 76 81 public MulticastSocket() throws IOException 77 82 { … … 79 84 } 80 85 81 /** 82 * Create a multicast socket bound to the specified port 83 * 84 * @param The port to bind to 85 * 86 * @exception IOException If an error occurs 87 */ 86 /** 87 * Create a multicast socket bound to the specified port 88 * 89 * @param port The port to bind to 90 * 91 * @exception IOException If an error occurs 92 * @exception SecurityException If a security manager exists and its 93 * checkListen method doesn't allow the operation 94 */ 88 95 public MulticastSocket(int port) throws IOException 89 96 { … … 91 98 } 92 99 93 /** 94 * Returns the interface being used for multicast packets 95 * 96 * @return The multicast interface 97 * 98 * @exception SocketException If an error occurs 99 */ 100 /** 101 * Create a multicast socket bound to the specified SocketAddress. 102 * 103 * @param address The SocketAddress the multicast socket will be bound to 104 * 105 * @exception IOException If an error occurs 106 * @exception SecurityException If a security manager exists and its 107 * checkListen method doesn't allow the operation 108 * 109 * @since 1.4 110 */ 111 public MulticastSocket(SocketAddress address) throws IOException 112 { 113 super(address); 114 } 115 116 /** 117 * Returns the interface being used for multicast packets 118 * 119 * @return The multicast interface 120 * 121 * @exception SocketException If an error occurs 122 */ 100 123 public InetAddress getInterface() throws SocketException 101 124 { 102 // FIXME: Is it possible that an InetAddress wasn't returned from getOption?103 125 return (InetAddress) impl.getOption(SocketOptions.IP_MULTICAST_IF); 104 126 } 105 127 106 /** 107 * Returns the current value of the "Time to Live" option. This is the 108 * number of hops a packet can make before it "expires". This method id 109 * deprecated. Use <code>getTimeToLive</code> instead. 110 * 111 * @return The TTL value 112 * 113 * @exception IOException If an error occurs 114 * 115 * @deprecated Replaced by getTimeToLive() in Java 1.2 116 */ 128 /** 129 * Returns the current value of the "Time to Live" option. This is the 130 * number of hops a packet can make before it "expires". This method id 131 * deprecated. Use <code>getTimeToLive</code> instead. 132 * 133 * @return The TTL value 134 * 135 * @exception IOException If an error occurs 136 * 137 * @deprecated 1.2 Replaced by getTimeToLive() 138 * 139 * @see Multicastsocket:getTimeToLive 140 */ 117 141 public byte getTTL() throws IOException 118 142 { … … 123 147 } 124 148 125 /**126 * Returns the current value of the "Time to Live" option. This is the127 * number of hops a packet can make before it "expires".128 *129 * @return The TTL value130 *131 * @exception IOException If an error occurs132 *133 * @since Java1.2134 */149 /** 150 * Returns the current value of the "Time to Live" option. This is the 151 * number of hops a packet can make before it "expires". 152 * 153 * @return The TTL value 154 * 155 * @exception IOException If an error occurs 156 * 157 1.2 158 */ 135 159 public int getTimeToLive() throws IOException 136 160 { … … 138 162 } 139 163 140 /** 141 * Sets the interface to use for multicast packets. 142 * 143 * @param addr The new interface to use 144 * 145 * @exception SocketException If an error occurs 146 */ 147 public void setInterface(InetAddress inf) throws SocketException 148 { 149 impl.setOption(SocketOptions.IP_MULTICAST_IF, inf); 150 } 151 152 /** 153 * Sets the "Time to Live" value for a socket. The value must be between 154 * 1 and 255. 155 * 156 * @param ttl The new TTL value 157 * 158 * @exception IOException If an error occurs 159 * 160 * @deprecated Replaced by <code>setTimeToLive</code> in Java 1.2 161 */ 164 /** 165 * Sets the interface to use for sending multicast packets. 166 * 167 * @param addr The new interface to use. 168 * 169 * @exception SocketException If an error occurs. 170 * 171 * @since 1.4 172 */ 173 public void setInterface(InetAddress addr) throws SocketException 174 { 175 impl.setOption(SocketOptions.IP_MULTICAST_IF, addr); 176 } 177 178 /** 179 * Sets the local network interface used to send multicast messages 180 * 181 * @param netIF The local network interface used to send multicast messages 182 * 183 * @exception SocketException If an error occurs 184 * 185 * @see MulticastSocket:getNetworkInterface 186 * 187 * @since 1.4 188 */ 189 public void setNetworkInterface(NetworkInterface netIf) 190 throws SocketException 191 { 192 if (impl == null) 193 throw new SocketException ( 194 "MulticastSocket: Cant access socket implementation"); 195 196 Enumeration e = netIf.getInetAddresses (); 197 198 if (!e.hasMoreElements ()) 199 throw new SocketException ("MulticastSocket: Error"); 200 201 InetAddress address = (InetAddress) e.nextElement (); 202 impl.setOption (SocketOptions.IP_MULTICAST_IF, address); 203 } 204 205 /** 206 * Gets the local network interface which is used to send multicast messages 207 * 208 * @return The local network interface to send multicast messages 209 * 210 * @exception SocketException If an error occurs 211 * 212 * @see MulticastSocket:setNetworkInterface 213 * 214 * @since 1.4 215 */ 216 public NetworkInterface getNetworkInterface() 217 throws SocketException 218 { 219 if (impl == null) 220 throw new SocketException ( 221 "MulticastSocket: Cant access socket implementation"); 222 223 InetAddress address = 224 (InetAddress) impl.getOption (SocketOptions.IP_MULTICAST_IF); 225 NetworkInterface netIf = NetworkInterface.getByInetAddress (address); 226 227 return netIf; 228 } 229 230 /** 231 * Disable/Enable local loopback of multicast packets. The option is used by 232 * the platform's networking code as a hint for setting whether multicast 233 * data will be looped back to the local socket. 234 * 235 * Because this option is a hint, applications that want to verify what 236 * loopback mode is set to should call #getLoopbackMode 237 * 238 * @param disable True to disable loopback mode 239 * 240 * @exception SocketException If an error occurs 241 * 242 * @since 1.4 243 */ 244 public void setLoopbackMode(boolean disable) throws SocketException 245 { 246 if (impl == null) 247 throw new SocketException ( 248 "MulticastSocket: Cant access socket implementation"); 249 250 impl.setOption (SocketOptions.IP_MULTICAST_LOOP, new Boolean (disable)); 251 } 252 253 /** 254 * Checks if local loopback mode is enabled or not 255 * 256 * @exception SocketException If an error occurs 257 * 258 * @since 1.4 259 */ 260 public boolean getLoopbackMode() throws SocketException 261 { 262 Object obj = impl.getOption (SocketOptions.IP_MULTICAST_LOOP); 263 264 if (obj instanceof Boolean) 265 return ((Boolean) obj).booleanValue (); 266 else 267 throw new SocketException ("Unexpected type"); 268 } 269 270 /** 271 * Sets the "Time to Live" value for a socket. The value must be between 272 * 1 and 255. 273 * 274 * @param ttl The new TTL value 275 * 276 * @exception IOException If an error occurs 277 * 278 * @deprecated 1.2 Replaced by <code>setTimeToLive</code> 279 * 280 * @see MulticastSocket:setTimeToLive 281 */ 162 282 public void setTTL(byte ttl) throws IOException 163 283 { … … 168 288 } 169 289 170 /**171 * Sets the "Time to Live" value for a socket. The value must be between172 * 1 and 255.173 *174 * @param ttl The new TTL value175 *176 * @exception IOException If an error occurs177 *178 * @since Java1.2179 */290 /** 291 * Sets the "Time to Live" value for a socket. The value must be between 292 * 1 and 255. 293 * 294 * @param ttl The new TTL value 295 * 296 * @exception IOException If an error occurs 297 * 298 1.2 299 */ 180 300 public void setTimeToLive(int ttl) throws IOException 181 301 { … … 186 306 } 187 307 188 /** 189 * Joins the specified mulitcast group. 190 * 191 * @param addr The address of the group to join 192 * 193 * @exception IOException If an error occurs 194 */ 308 /** 309 * Joins the specified mulitcast group. 310 * 311 * @param addr The address of the group to join 312 * 313 * @exception IOException If an error occurs 314 * @exception SecurityException If a security manager exists and its 315 * checkMulticast method doesn't allow the operation 316 */ 195 317 public void joinGroup(InetAddress mcastaddr) throws IOException 196 318 { … … 205 327 } 206 328 207 /** 208 * Leaves the specified multicast group 209 * 210 * @param addr The address of the group to leave 211 * 212 * @exception IOException If an error occurs 213 */ 329 /** 330 * Leaves the specified multicast group 331 * 332 * @param addr The address of the group to leave 333 * 334 * @exception IOException If an error occurs 335 * @exception SecurityException If a security manager exists and its 336 * checkMulticast method doesn't allow the operation 337 */ 214 338 public void leaveGroup(InetAddress mcastaddr) throws IOException 215 339 { … … 224 348 } 225 349 226 /** 227 * Sends a packet of data to a multicast address with a TTL that is 228 * different from the default TTL on this socket. The default TTL for 229 * the socket is not changed. 230 * 231 * @param packet The packet of data to send 232 * @param ttl The TTL for this packet 233 * 234 * @exception IOException If an error occurs 235 */ 350 /** 351 * Joins the specified mulitcast group on a specified interface. 352 * 353 * @param mcastaddr The multicast address to join 354 * @param netIf The local network interface to receive the multicast 355 * messages on or null to defer the interface set by #setInterface or 356 * #setNetworkInterface 357 * 358 * @exception IOException If an error occurs 359 * @exception IllegalArgumentException If address type is not supported 360 * @exception SecurityException If a security manager exists and its 361 * checkMulticast method doesn't allow the operation 362 * 363 * @see MulticastSocket:setInterface 364 * @see MulticastSocket:setNetworkInterface 365 * 366 * @since 1.4 367 */ 368 public void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) 369 throws IOException 370 { 371 if (! (mcastaddr instanceof InetSocketAddress)) 372 throw new IllegalArgumentException ("SocketAddress type not supported"); 373 374 InetSocketAddress tmp = (InetSocketAddress) mcastaddr; 375 376 if (! tmp.getAddress ().isMulticastAddress ()) 377 throw new IOException ("Not a Multicast address"); 378 379 SecurityManager s = System.getSecurityManager (); 380 if (s != null) 381 s.checkMulticast (tmp.getAddress ()); 382 383 impl.joinGroup (mcastaddr, netIf); 384 } 385 386 /** 387 * Leaves the specified mulitcast group on a specified interface. 388 * 389 * @param mcastaddr The multicast address to leave 390 * @param netIf The local networki interface or null to defer to the 391 * interface set by setInterface or setNetworkInterface 392 * 393 * @exception IOException If an error occurs 394 * @exception IllegalArgumentException If address type is not supported 395 * @exception SecurityException If a security manager exists and its 396 * checkMulticast method doesn't allow the operation 397 * 398 * @see MulticastSocket:setInterface 399 * @see MulticastSocket:setNetworkInterface 400 * 401 * @since 1.4 402 */ 403 public void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) 404 throws IOException 405 { 406 InetSocketAddress tmp = (InetSocketAddress) mcastaddr; 407 408 if (! tmp.getAddress ().isMulticastAddress ()) 409 throw new IOException ("Not a Multicast address"); 410 411 SecurityManager s = System.getSecurityManager (); 412 if (s != null) 413 s.checkMulticast (tmp.getAddress ()); 414 415 impl.leaveGroup (mcastaddr, netIf); 416 } 417 418 /** 419 * Sends a packet of data to a multicast address with a TTL that is 420 * different from the default TTL on this socket. The default TTL for 421 * the socket is not changed. 422 * 423 * @param packet The packet of data to send 424 * @param ttl The TTL for this packet 425 * 426 * @exception IOException If an error occurs 427 * @exception SecurityException If a security manager exists and its 428 * checkConnect or checkMulticast method doesn't allow the operation 429 */ 236 430 public synchronized void send(DatagramPacket p, byte ttl) throws IOException 237 431 { -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.
