NCSA Portfolio

ncsa.net
Class MulticastHandler

java.lang.Object
  |
  +--ncsa.net.Handler
        |
        +--ncsa.net.MulticastHandler

public class MulticastHandler
extends Handler
implements java.lang.Runnable

A MulticastHandler sends data to a multicast group. The specified Customer object receives data on that multicast group. The Customer is then responsible for dealing with the incoming data. Usage:

Transform3d transform = InterestingObject.getTransform();
TransformGroupCustomer cust = new TransformGroupCustomer(transform);
MulticastHandler multi = new MulticastHandler("128.8.2.2", 3120, cust);
multi.begin();
.
.
.
multi.transmit(buf, len);
.
.
.
multi.end();
In the example above, we wish to send transform information out on a multicast group, and have all other MulticastHandlers listening on the subnet 128.8.2.2 on port 3120 to set the Transform3D for the object InterestingObject when they receive data.

This is used to allow multiple applications working on a subnet to share the same movements. When one application changes a transform and transmits it, all the other applications will change their transforms to match. This object is generally used when many transformations are happening and the user wishes to have continuously updating displays on all subscribed devices.

See Also:
TransformGroupCustomer

Constructor Summary
MulticastHandler(java.lang.String subnet, int port, Customer c)
          Create a MulticastHandler
 
Method Summary
 void begin()
          Initialize the multicast socket, and start the receiving thread.
 void end()
          Stop the receiving thread, and leave the multicast group
 void run()
          The main thread loop that receives incoming data
 void setLoopback(boolean loopback)
          Sets the loopback.
 void transmit(byte[] buf, int len)
          Send data to the multicast group.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MulticastHandler

public MulticastHandler(java.lang.String subnet,
                        int port,
                        Customer c)
Create a MulticastHandler
Parameters:
subnet - The multicast subnet to broadcast data
port - The subnet's port to use.
c - The Customer which handles incoming data
Method Detail

setLoopback

public void setLoopback(boolean loopback)
Sets the loopback. If false we don't receive messages we sent.
Parameters:
loopback - Whether we want to see stuff we sent or not.

begin

public void begin()
Initialize the multicast socket, and start the receiving thread.
Overrides:
begin in class Handler

end

public void end()
Stop the receiving thread, and leave the multicast group
Overrides:
end in class Handler

transmit

public void transmit(byte[] buf,
                     int len)
Send data to the multicast group. The data sent is from buffer elements 0 through len.
Overrides:
transmit in class Handler
Parameters:
buf - The outgoing data buffer
len - The length of data to send.

run

public void run()
The main thread loop that receives incoming data
Specified by:
run in interface java.lang.Runnable

NCSA Portfolio

NCSA Portfolio, Copyright 1997-1999, National Center for Supercomputing Applications, University of Illinois Urbana-Champaign, All Rights Reserved