home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / net / MulticastSocket.java < prev    next >
Encoding:
Java Source  |  1997-01-27  |  3.5 KB  |  105 lines

  1. /*
  2.  * @(#)MulticastSocket.java    1.11 96/03/13 Pavani Diwanji
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package sun.net;
  21.  
  22. import java.io.IOException;
  23. import java.io.InterruptedIOException;
  24. import java.net.SocketException;
  25. import java.net.DatagramPacket;
  26. import java.net.*;
  27.  
  28. /**
  29.  * The multicast datagram socket class 
  30.  * @author Pavani Diwanji
  31. */
  32. public final
  33. class MulticastSocket extends java.net.DatagramSocket {
  34.     
  35.     static {
  36.         System.loadLibrary("javart");
  37.     }
  38.  
  39.     public MulticastSocket() throws SocketException {
  40.     super();
  41.     }
  42.     public MulticastSocket(int port) throws SocketException {
  43.     super(port);
  44.     }
  45.     
  46.     /**
  47.      * Joins a multicast group.
  48.      * @param mcastaddr is the multicast address to join 
  49.      * @exception SocketException: when address is not a multicast address
  50.      * TBD: subclass of socket exception i.e. BadAddress
  51.      */
  52.     public void joinGroup(InetAddress mcastaddr) throws SocketException {
  53.     // TBD: Security check plugs in here, if we want.
  54.     // Its not needed as we do a check on every send and receive anyways.
  55.     multicastJoin(mcastaddr);
  56.     }
  57.  
  58.     /**
  59.      * Leave a multicast group.
  60.      * @param mcastaddr is the multicast address to leave
  61.      * @exception SocketException: when address is not a multicast address
  62.      * TBD: subclass of socket exception i.e. BadAddress
  63.      */
  64.     public void leaveGroup(InetAddress mcastaddr) throws SocketException {
  65.     // TBD: Security check plugs in here, if we want.
  66.     // Its not needed as we do a check on every send and receive anyways.
  67.     multicastLeave(mcastaddr);
  68.     }
  69.     
  70.     /**
  71.      * Sends a datagram packet to the destination
  72.      * @param p    the packet to be sent
  73.      * @param ttl optional time to live for multicast packet.
  74.      * default ttl is 1.
  75.      * @exception IOException i/o error occurred
  76.      * @exception SocketException occurs while setting ttl.
  77.      */
  78.  
  79.     public synchronized void send(DatagramPacket p, byte ttl)
  80.      throws IOException, SocketException {
  81.  
  82.     // check the address is ok wiht the security manager on every send.
  83.     // since here the to_address is going to be multicast address
  84.     // we need a seperate hook in the security manager i.e
  85.     // maxttl = security.checkMulticast()
  86.         // we need to make sure that the ttl that user sets is less
  87.     // than the allowed maxttl.
  88.     SecurityManager security = System.getSecurityManager();
  89.     if (security != null) {
  90.         security.checkConnect(p.getAddress().getHostAddress(), p.getPort());
  91.     }
  92.  
  93.     // set the ttl
  94.     setTTL(ttl);
  95.     // call the datagram method to send
  96.     send(p);
  97.     }
  98.     
  99.     private native void setTTL(byte ttl);
  100.     private native void multicastJoin(InetAddress inetaddr);
  101.     private native void multicastLeave(InetAddress inetaddr);
  102.  
  103. }
  104.  
  105.