|
Project JXTA | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.net.DatagramSocket
java.net.MulticastSocket
net.jxta.socket.JxtaMulticastSocket
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 Credential |
credential
|
protected StructuredDocument |
credentialDoc
|
static String |
DATATAG
|
protected PeerGroup |
group
|
protected InputPipe |
in
|
protected InetAddress |
localAddress
|
static String |
NAMESPACE
|
protected OutputPipe |
outputPipe
|
protected PipeAdvertisement |
pipeAdv
|
protected PipeService |
pipeSvc
|
protected net.jxta.impl.util.ProducerBiasedQueue |
queue
|
protected SocketAddress |
socketAddress
|
static String |
SRCIDTAG
|
Constructor Summary | |
JxtaMulticastSocket(PeerGroup group,
PipeAdvertisement pipeAd)
Create a multicast socket and bind it to a specific pipe within specified peer group |
Method Summary | |
void |
bind(SocketAddress addr)
|
void |
close()
Closes this MutlicastSocket. |
protected static StructuredDocument |
getCredDoc(PeerGroup group)
Obtain the credential doc from the group object |
InetAddress |
getLocalAddress()
|
SocketAddress |
getLocalSocketAddress()
|
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(PeerGroup group,
PipeAdvertisement pipeAd)
joins MutlicastSocket to specified pipe within the context of group |
void |
pipeMsgEvent(PipeMsgEvent event)
Called for each pipe message event that occurs. |
void |
receive(DatagramPacket packet)
|
void |
send(DatagramPacket packet)
|
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 |
public static final String NAMESPACE
public static final String DATATAG
public static final String SRCIDTAG
protected PipeAdvertisement pipeAdv
protected PipeService pipeSvc
protected InputPipe in
protected PeerGroup group
protected SocketAddress socketAddress
protected InetAddress localAddress
protected OutputPipe outputPipe
protected boolean closed
protected boolean bound
protected net.jxta.impl.util.ProducerBiasedQueue queue
protected Credential credential
protected StructuredDocument credentialDoc
Constructor Detail |
public JxtaMulticastSocket(PeerGroup group, PipeAdvertisement pipeAd) throws IOException
group
- group contextpipeAd
- PipeAdvertisement
IOException
- if an io error occursMethod Detail |
public void joinGroup(PeerGroup group, PipeAdvertisement pipeAd) throws IOException
group
- group contextpipeAd
- PipeAdvertisement
IOException
- if an io error occursprotected static StructuredDocument getCredDoc(PeerGroup group)
group
- group context
public boolean isBound()
public void close()
IOException
- if an I/O error occurs when closing this
socket.public void pipeMsgEvent(PipeMsgEvent event)
pipeMsgEvent
in interface PipeMsgListener
event
- The event being received.public int getSoTimeout()
IOException
- if an I/O error occurspublic void setSoTimeout(int timeout) throws SocketException
timeout
- The new soTimeout value
IOException
- if an I/O error occurs
SocketException
public boolean isClosed()
public void send(DatagramPacket packet) throws IOException
IOException
public void receive(DatagramPacket packet) throws IOException
IOException
public InetAddress getLocalAddress()
public SocketAddress getLocalSocketAddress()
public void bind(SocketAddress addr) throws SocketException
SocketException
|
JXTA J2SE | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |