hypercast
Class MulticastSocketMasquerade

java.lang.Object
  |
  +--java.net.DatagramSocket
        |
        +--java.net.MulticastSocket
              |
              +--hypercast.MulticastSocketMasquerade

public class MulticastSocketMasquerade
extends java.net.MulticastSocket

A class for easily porting old Java Multicast programs to Hypercast. Ideally, this should be constructed by calling HyperCastConfig.createJavaMulticastSocket().

NOTE: Some code may need to be modified if it uses functions: getInterface, getLocalAddress, getLocalPort, getTTL, setTTL, and setInterface.

If you want to skip the nice simple interface given by HyperCastConfig:

Constructor for MulticastSocket should be replaced by constructor for a MulticastSocketMasquerade.

MulticastSocket sock = new MulticastSocket();

Should become:

MulticastSocket sock = null; try { sock = new MulticastSocketMasquerade(); } catch (Exception ignored) { } sock.setOLSocket( ... );

At which point, the variable sock can be used as normal.


Constructor Summary
MulticastSocketMasquerade()
          Create the datagram socket.
 
Method Summary
 void close()
          leave the group.
 java.net.InetAddress getInterface()
          returns local IP Address.
 java.net.InetAddress getLocalAddress()
          returns local IP Address.
 int getLocalPort()
          Returns designated port number (probably zero).
 int getSoTimeout()
          Returns SoTimeout of Hypercast Socket.
 void joinGroup(java.net.InetAddress mcastaddr)
          Joins overlay multicast group.
 void leaveGroup(java.net.InetAddress mcastaddr)
          Leaves overlay multicast group.
 void receive(java.net.DatagramPacket p)
          Received I_OverlayMessages are translated into DatagramPackets and returned.
 void send(java.net.DatagramPacket p)
          Datagram Packet is translated into an I_OverlayMessage and sent.
 void setInterface(java.net.InetAddress inf)
          ignored.
 void setOverlaySocket(hypercast.I_OverlaySocket olSocket)
          Sets the socket that messages should be sent over and gotten from.
 void setSoTimeout(int timeout)
          Sets Hypercast Socket's SoTimeout
 
Methods inherited from class java.net.MulticastSocket
getLoopbackMode, getNetworkInterface, getTimeToLive, getTTL, joinGroup, leaveGroup, send, setLoopbackMode, setNetworkInterface, setTimeToLive, setTTL
 
Methods inherited from class java.net.DatagramSocket
bind, connect, connect, disconnect, getBroadcast, getChannel, getInetAddress, getLocalSocketAddress, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getTrafficClass, isBound, isClosed, isConnected, setBroadcast, setDatagramSocketImplFactory, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setTrafficClass
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MulticastSocketMasquerade

public MulticastSocketMasquerade()
                          throws java.io.IOException
Create the datagram socket.

Throws:
java.io.IOException - This should be caught and ignored.
Method Detail

setOverlaySocket

public void setOverlaySocket(hypercast.I_OverlaySocket olSocket)
Sets the socket that messages should be sent over and gotten from. This function must be called immediately after the constructor.


close

public void close()
leave the group.

Overrides:
close in class java.net.DatagramSocket

getInterface

public java.net.InetAddress getInterface()
                                  throws java.net.SocketException
returns local IP Address.

Overrides:
getInterface in class java.net.MulticastSocket
java.net.SocketException

getLocalAddress

public java.net.InetAddress getLocalAddress()
returns local IP Address.

Overrides:
getLocalAddress in class java.net.DatagramSocket

getLocalPort

public int getLocalPort()
Returns designated port number (probably zero).

Overrides:
getLocalPort in class java.net.DatagramSocket

getSoTimeout

public int getSoTimeout()
Returns SoTimeout of Hypercast Socket.

Overrides:
getSoTimeout in class java.net.DatagramSocket

joinGroup

public void joinGroup(java.net.InetAddress mcastaddr)
               throws java.io.IOException
Joins overlay multicast group.

Overrides:
joinGroup in class java.net.MulticastSocket
java.io.IOException

leaveGroup

public void leaveGroup(java.net.InetAddress mcastaddr)
                throws java.io.IOException
Leaves overlay multicast group.

Overrides:
leaveGroup in class java.net.MulticastSocket
java.io.IOException

receive

public void receive(java.net.DatagramPacket p)
             throws java.io.IOException
Received I_OverlayMessages are translated into DatagramPackets and returned.

Overrides:
receive in class java.net.DatagramSocket
Throws:
java.io.IOException - is never thrown.

send

public void send(java.net.DatagramPacket p)
          throws java.io.IOException
Datagram Packet is translated into an I_OverlayMessage and sent. A new byte array is created, so that src IP Address can be stuck at end.

Overrides:
send in class java.net.DatagramSocket
Throws:
java.io.IOException - is never thrown.

setInterface

public void setInterface(java.net.InetAddress inf)
                  throws java.net.SocketException
ignored.

Overrides:
setInterface in class java.net.MulticastSocket
java.net.SocketException

setSoTimeout

public void setSoTimeout(int timeout)
                  throws java.net.SocketException
Sets Hypercast Socket's SoTimeout

Overrides:
setSoTimeout in class java.net.DatagramSocket
java.net.SocketException