equal
deleted
inserted
replaced
79 * @author Pavani Diwanji |
79 * @author Pavani Diwanji |
80 * @since JDK1.1 |
80 * @since JDK1.1 |
81 */ |
81 */ |
82 public |
82 public |
83 class MulticastSocket extends DatagramSocket { |
83 class MulticastSocket extends DatagramSocket { |
|
84 |
|
85 /** |
|
86 * Used on some platforms to record if an outgoing interface |
|
87 * has been set for this socket. |
|
88 */ |
|
89 private boolean interfaceSet; |
|
90 |
84 /** |
91 /** |
85 * Create a multicast socket. |
92 * Create a multicast socket. |
86 * |
93 * |
87 * <p>If there is a security manager, |
94 * <p>If there is a security manager, |
88 * its <code>checkListen</code> method is first called |
95 * its <code>checkListen</code> method is first called |
301 |
308 |
302 if (!mcastaddr.isMulticastAddress()) { |
309 if (!mcastaddr.isMulticastAddress()) { |
303 throw new SocketException("Not a multicast address"); |
310 throw new SocketException("Not a multicast address"); |
304 } |
311 } |
305 |
312 |
|
313 /** |
|
314 * required for some platforms where it's not possible to join |
|
315 * a group without setting the interface first. |
|
316 */ |
|
317 NetworkInterface defaultInterface = NetworkInterface.getDefault(); |
|
318 |
|
319 if (!interfaceSet && defaultInterface != null) { |
|
320 setNetworkInterface(defaultInterface); |
|
321 } |
|
322 |
306 getImpl().join(mcastaddr); |
323 getImpl().join(mcastaddr); |
307 } |
324 } |
308 |
325 |
309 /** |
326 /** |
310 * Leave a multicast group. Its behavior may be affected by |
327 * Leave a multicast group. Its behavior may be affected by |
451 } |
468 } |
452 checkAddress(inf, "setInterface"); |
469 checkAddress(inf, "setInterface"); |
453 synchronized (infLock) { |
470 synchronized (infLock) { |
454 getImpl().setOption(SocketOptions.IP_MULTICAST_IF, inf); |
471 getImpl().setOption(SocketOptions.IP_MULTICAST_IF, inf); |
455 infAddress = inf; |
472 infAddress = inf; |
|
473 interfaceSet = true; |
456 } |
474 } |
457 } |
475 } |
458 |
476 |
459 /** |
477 /** |
460 * Retrieve the address of the network interface used for |
478 * Retrieve the address of the network interface used for |
533 throws SocketException { |
551 throws SocketException { |
534 |
552 |
535 synchronized (infLock) { |
553 synchronized (infLock) { |
536 getImpl().setOption(SocketOptions.IP_MULTICAST_IF2, netIf); |
554 getImpl().setOption(SocketOptions.IP_MULTICAST_IF2, netIf); |
537 infAddress = null; |
555 infAddress = null; |
|
556 interfaceSet = true; |
538 } |
557 } |
539 } |
558 } |
540 |
559 |
541 /** |
560 /** |
542 * Get the multicast network interface set. |
561 * Get the multicast network interface set. |