edu.virginia.cs.mng.hypercast
Class MulticastSocketMasquerade

java.lang.Object
  |
  +--java.net.DatagramSocket
        |
        +--java.net.MulticastSocket
              |
              +--edu.virginia.cs.mng.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 OverlaySocketConfig.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 OverlaySocketConfig:

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.


Field Summary
private  IP_Address localAddress
          The source address for all messages sent by this socket.
private  I_OverlaySocket overlaySocket
          The socket that messages should be sent to and gotten from.
(package private) static int portNumber
          Port number that should be reported.
 
Fields inherited from class java.net.MulticastSocket
ttlLock
 
Fields inherited from class java.net.DatagramSocket
connected, connectedAddress, connectedPort, impl, implClass
 
Constructor Summary
MulticastSocketMasquerade()
          Create the datagram socket.
 
Method Summary
 void close()
          leave the group.
protected  void finalize()
          Ignored.
 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 send(java.net.DatagramPacket p, byte ttl)
          Same as Send, but with specific TTL.
 void setInterface(java.net.InetAddress inf)
          ignored.
 void setOverlaySocket(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
create, getTimeToLive, getTTL, setTimeToLive, setTTL
 
Methods inherited from class java.net.DatagramSocket
, connect, disconnect, getInetAddress, getPort, getReceiveBufferSize, getSendBufferSize, setReceiveBufferSize, setSendBufferSize
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

overlaySocket

private I_OverlaySocket overlaySocket
The socket that messages should be sent to and gotten from.

localAddress

private IP_Address localAddress
The source address for all messages sent by this socket.

portNumber

static final int portNumber
Port number that should be reported.
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(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

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

leaveGroup

public void leaveGroup(java.net.InetAddress mcastaddr)
                throws java.io.IOException
Leaves overlay multicast group.
Overrides:
leaveGroup in class java.net.MulticastSocket

receive

public void receive(java.net.DatagramPacket p)
             throws java.io.IOException
Received I_OverlayMessages are translated into DatagramPackets and returned.
Throws:
java.io.IOException - is never thrown.
Overrides:
receive in class java.net.DatagramSocket

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.
Throws:
java.io.IOException - is never thrown.
Overrides:
send in class java.net.DatagramSocket

send

public void send(java.net.DatagramPacket p,
                 byte ttl)
          throws java.io.IOException
Same as Send, but with specific TTL.
Parameters:
ttl - The time to live for this packet
Throws:
java.io.IOException - is never thrown.
Overrides:
send in class java.net.MulticastSocket

setInterface

public void setInterface(java.net.InetAddress inf)
                  throws java.net.SocketException
ignored.
Overrides:
setInterface in class java.net.MulticastSocket

setSoTimeout

public void setSoTimeout(int timeout)
                  throws java.net.SocketException
Sets Hypercast Socket's SoTimeout
Overrides:
setSoTimeout in class java.net.DatagramSocket

finalize

protected void finalize()
Ignored.
Overrides:
finalize in class java.lang.Object