Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

net.jxta.socket
Class JxtaMulticastSocket  view JxtaMulticastSocket download JxtaMulticastSocket.java

java.lang.Object
  extended byjava.net.DatagramSocket
      extended byjava.net.MulticastSocket
          extended bynet.jxta.socket.JxtaMulticastSocket
All Implemented Interfaces:
java.util.EventListener, net.jxta.pipe.PipeMsgListener

public class JxtaMulticastSocket
extends java.net.MulticastSocket
implements net.jxta.pipe.PipeMsgListener

The JxtaMulticastSocket class is useful for sending and receiving JXTA multicast packets. A JxtaMulticastSocket is a (UDP) DatagramSocket, with additional capabilities for joining "groups" of other multicast hosts on the internet. A multicast group is specified within the context of PeerGroup and a propagate pipe advertisement. One would join a multicast group by first creating a MulticastSocket with the desired peer group and pipe advertisement : // join a Multicast group and send the group salutations ... String msg = "Hello"; InetAddress group = InetAddress.getByName("228.5.6.7"); MulticastSocket s = new JxtaMulticastSocket(peergroup, propPipeAdv); //We are joined at this point DatagramPacket hi = new DatagramPacket(msg.getBytes(), msg.length()); s.send(hi); // get their responses! byte[] buf = new byte[1000]; DatagramPacket recv = new DatagramPacket(buf, buf.length); s.receive(recv); ... // OK, I'm done talking - leave the group... s.close(); One can also respond only to the sender of the datagram as follows DatagramPacket res = new DatagramPacket(response.getBytes(), response.length()); res.setAddress(recv.getAddress()); s.send(res); When one sends a message to a multicast group, all subscribing recipients to that peergroup and pipe receive the message (including themselves) When a socket subscribes to a multicast group/port, it receives datagrams sent by other hosts to the group/pipe, as do all other members of the group and pipe. A socket relinquishes membership in a group by the close() method. Multiple MulticastSocket's may subscribe to a multicast group and pipe concurrently, and they will all receive group datagrams. When a datagram is sent it carries along with the peerid of the sender. The PeerID is represented as a InetAddress in the form of host/ipadress where host name is the peerid, and ip address is always represented as 0.0.0.0 since it is meaningless in the context of JXTA. e.g of InetAddress resembles the following: uuid-59616261646162614A787461503250339C6014B0F21A49DBBDF2ADBDDBCB314703/0.0.0.0


Field Summary
protected  boolean bound
           
protected  boolean closed
           
protected  net.jxta.credential.Credential credential
           
protected  net.jxta.document.StructuredDocument credentialDoc
           
static java.lang.String DATATAG
           
private  byte[] fauxip
           
protected  net.jxta.peergroup.PeerGroup group
           
protected  net.jxta.pipe.InputPipe in
           
private  boolean jxtamode
           
protected  java.net.InetAddress localAddress
           
private static org.apache.log4j.Logger LOG
           
static java.lang.String NAMESPACE
           
protected  net.jxta.pipe.OutputPipe outputPipe
           
protected  net.jxta.protocol.PipeAdvertisement pipeAdv
           
protected  net.jxta.pipe.PipeService pipeSvc
           
protected  net.jxta.impl.util.ProducerBiasedQueue queue
           
protected  java.net.SocketAddress socketAddress
           
private  net.jxta.endpoint.MessageElement srcElement
           
static java.lang.String SRCIDTAG
           
private  int timeout
           
 
Fields inherited from class java.net.DatagramSocket
 
Constructor Summary
JxtaMulticastSocket(net.jxta.peergroup.PeerGroup group, net.jxta.protocol.PipeAdvertisement pipeAd)
          Create a multicast socket and bind it to a specific pipe within specified peer group
 
Method Summary
 void bind(java.net.SocketAddress addr)
          null
private  void checkState()
          Throws a SocketException if closed or not bound
 void close()
          Closes this MutlicastSocket.
protected static net.jxta.document.StructuredDocument getCredDoc(net.jxta.peergroup.PeerGroup group)
          Obtain the credential doc from the group object
 java.net.InetAddress getLocalAddress()
          null
 java.net.SocketAddress getLocalSocketAddress()
          null
 int getSoTimeout()
          Gets the Timeout attribute of the JxtaMulticastSocket
 boolean isBound()
          Returns the binding state of the MutlicastSocket.
 boolean isClosed()
          Returns the closed state of the JxtaMulticastSocket.
 void joinGroup(net.jxta.peergroup.PeerGroup group, net.jxta.protocol.PipeAdvertisement pipeAd)
          joins MutlicastSocket to specified pipe within the context of group
 void pipeMsgEvent(net.jxta.pipe.PipeMsgEvent event)
          null
 void receive(java.net.DatagramPacket packet)
          null
 void send(java.net.DatagramPacket packet)
          null
 void setSoTimeout(int timeout)
          Sets the Timeout attribute of the JxtaMulticastSocket a timeout of 0 blocks forever, by default this Socket's timeout is set to 0
 
Methods inherited from class java.net.MulticastSocket
getInterface, getLoopbackMode, getNetworkInterface, getTimeToLive, getTTL, joinGroup, joinGroup, leaveGroup, leaveGroup, send, setInterface, setLoopbackMode, setNetworkInterface, setTimeToLive, setTTL
 
Methods inherited from class java.net.DatagramSocket
connect, connect, disconnect, getBroadcast, getChannel, getInetAddress, getLocalPort, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getTrafficClass, isConnected, setBroadcast, setDatagramSocketImplFactory, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setTrafficClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final org.apache.log4j.Logger LOG

NAMESPACE

public static final java.lang.String NAMESPACE
See Also:
Constant Field Values

DATATAG

public static final java.lang.String DATATAG
See Also:
Constant Field Values

SRCIDTAG

public static final java.lang.String SRCIDTAG
See Also:
Constant Field Values

pipeAdv

protected net.jxta.protocol.PipeAdvertisement pipeAdv

pipeSvc

protected net.jxta.pipe.PipeService pipeSvc

in

protected net.jxta.pipe.InputPipe in

group

protected net.jxta.peergroup.PeerGroup group

socketAddress

protected java.net.SocketAddress socketAddress

localAddress

protected java.net.InetAddress localAddress

outputPipe

protected net.jxta.pipe.OutputPipe outputPipe

closed

protected boolean closed

bound

protected boolean bound

queue

protected net.jxta.impl.util.ProducerBiasedQueue queue

credential

protected net.jxta.credential.Credential credential

credentialDoc

protected net.jxta.document.StructuredDocument credentialDoc

timeout

private int timeout

fauxip

private byte[] fauxip

jxtamode

private boolean jxtamode

srcElement

private net.jxta.endpoint.MessageElement srcElement
Constructor Detail

JxtaMulticastSocket

public JxtaMulticastSocket(net.jxta.peergroup.PeerGroup group,
                           net.jxta.protocol.PipeAdvertisement pipeAd)
                    throws java.io.IOException
Create a multicast socket and bind it to a specific pipe within specified peer group

Method Detail

joinGroup

public void joinGroup(net.jxta.peergroup.PeerGroup group,
                      net.jxta.protocol.PipeAdvertisement pipeAd)
               throws java.io.IOException
joins MutlicastSocket to specified pipe within the context of group


getCredDoc

protected static net.jxta.document.StructuredDocument getCredDoc(net.jxta.peergroup.PeerGroup group)
Obtain the credential doc from the group object


isBound

public boolean isBound()
Returns the binding state of the MutlicastSocket.


close

public void close()
Closes this MutlicastSocket.


pipeMsgEvent

public void pipeMsgEvent(net.jxta.pipe.PipeMsgEvent event)
null

Specified by:
pipeMsgEvent in interface net.jxta.pipe.PipeMsgListener

getSoTimeout

public int getSoTimeout()
Gets the Timeout attribute of the JxtaMulticastSocket


setSoTimeout

public void setSoTimeout(int timeout)
                  throws java.net.SocketException
Sets the Timeout attribute of the JxtaMulticastSocket a timeout of 0 blocks forever, by default this Socket's timeout is set to 0


isClosed

public boolean isClosed()
Returns the closed state of the JxtaMulticastSocket.


checkState

private void checkState()
                 throws java.net.SocketException
Throws a SocketException if closed or not bound


send

public void send(java.net.DatagramPacket packet)
          throws java.io.IOException
null


receive

public void receive(java.net.DatagramPacket packet)
             throws java.io.IOException
null


getLocalAddress

public java.net.InetAddress getLocalAddress()
null


getLocalSocketAddress

public java.net.SocketAddress getLocalSocketAddress()
null


bind

public void bind(java.net.SocketAddress addr)
          throws java.net.SocketException
null