本文整理汇总了Java中java.net.MulticastSocket.joinGroup方法的典型用法代码示例。如果您正苦于以下问题:Java MulticastSocket.joinGroup方法的具体用法?Java MulticastSocket.joinGroup怎么用?Java MulticastSocket.joinGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.MulticastSocket
的用法示例。
在下文中一共展示了MulticastSocket.joinGroup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onResume
import java.net.MulticastSocket; //导入方法依赖的package包/类
@Override
protected void onResume() {
super.onResume();
fileReciveThread = new FileReciveThread();
fileReciveThread.start();
try {
socket = new MulticastSocket(portNum);
socket.setInterface(ip);
socket.setBroadcast(true);
group = InetAddress.getByName("224.0.0.1");
socket.joinGroup(new InetSocketAddress(group, portNum), networkInterface);
} catch (IOException e) {
e.printStackTrace();
}
}
示例2: PacketReceiver
import java.net.MulticastSocket; //导入方法依赖的package包/类
public PacketReceiver( MessageListener listener )
{
messageListener = listener; // set MessageListener
try // connect MulticastSocket to multicast address and port
{
// create new MulticastSocket
multicastSocket = new MulticastSocket(
MULTICAST_LISTENING_PORT );
// use InetAddress to get multicast group
multicastGroup = InetAddress.getByName( MULTICAST_ADDRESS );
// join multicast group to receive messages
multicastSocket.joinGroup( multicastGroup );
// set 5 second timeout when waiting for new packets
multicastSocket.setSoTimeout( 5000 );
} // end try
catch ( IOException ioException )
{
ioException.printStackTrace();
} // end catch
}
示例3: UDPread0
import java.net.MulticastSocket; //导入方法依赖的package包/类
UDPread0(int iport, String isrcName, String[] ichanName, int idt) {
port = iport;
srcName = isrcName;
chanName = ichanName;
try { //open port for incoming UDP
if(multiCast != null) {
System.err.println("Multicast address: "+multiCast);
ms = new MulticastSocket(port);
ms.joinGroup(InetAddress.getByName(multiCast));
}
else {
ds = new DatagramSocket(port);
// ds.setSoTimeout(10); // non-blocking timeout
}
} catch (Exception e) { e.printStackTrace(); }
}
示例4: multicast
import java.net.MulticastSocket; //导入方法依赖的package包/类
/**
*
* @param multicastIP for example, 224.X.X.X or 239.X.X.X
* @param port
* @param bs
*/
public static void multicast(final String multicastIP, final int port, final byte[] sendData){
final WifiManager wifi = getWiFiManager();
MulticastLock multicastLock = wifi.createMulticastLock(String.valueOf(System.currentTimeMillis()));
multicastLock.setReferenceCounted(true);
multicastLock.acquire();
try{
final MulticastSocket multicastSocket=new MulticastSocket(port);
multicastSocket.setLoopbackMode(true);
final InetAddress group = InetAddress.getByName(multicastIP);
multicastSocket.joinGroup(group);
final DatagramPacket packet=new DatagramPacket(sendData, sendData.length,group,port);
multicastSocket.send(packet);
}catch (final Throwable e) {
e.printStackTrace();
}
if (multicastLock != null) {
multicastLock.release();
multicastLock = null;
}
}
示例5: createSocket
import java.net.MulticastSocket; //导入方法依赖的package包/类
/**
* Creates multicast socket and joins multicast group.
*
* @throws IOException If fails to create socket or join multicast group.
* @return Multicast socket.
*/
private MulticastSocket createSocket() throws IOException {
MulticastSocket sock = new MulticastSocket(mcastPort);
sock.setLoopbackMode(false); // Use 'false' to enable support for more than one node on the same machine.
if (sockItf != null)
sock.setInterface(sockItf);
if (sock.getLoopbackMode())
U.warn(log, "Loopback mode is disabled which prevents nodes on the same machine from discovering " +
"each other.");
sock.joinGroup(mcastGrp);
if (ttl != -1)
sock.setTimeToLive(ttl);
return sock;
}
示例6: init
import java.net.MulticastSocket; //导入方法依赖的package包/类
synchronized public void init(NetworkInterface networkInterface,
Router router,
NetworkAddressFactory networkAddressFactory,
DatagramProcessor datagramProcessor) throws InitializationException {
this.router = router;
this.networkAddressFactory = networkAddressFactory;
this.datagramProcessor = datagramProcessor;
this.multicastInterface = networkInterface;
try {
log.info("Creating wildcard socket (for receiving multicast datagrams) on port: " + configuration.getPort());
multicastAddress = new InetSocketAddress(configuration.getGroup(), configuration.getPort());
socket = new MulticastSocket(configuration.getPort());
socket.setReuseAddress(true);
socket.setReceiveBufferSize(32768); // Keep a backlog of incoming datagrams if we are not fast enough
log.info("Joining multicast group: " + multicastAddress + " on network interface: " + multicastInterface.getDisplayName());
socket.joinGroup(multicastAddress, multicastInterface);
} catch (Exception ex) {
throw new InitializationException("Could not initialize " + getClass().getSimpleName() + ": " + ex);
}
}
示例7: Socket
import java.net.MulticastSocket; //导入方法依赖的package包/类
public Socket(MainWindow main) throws UnknownHostException {
this.main = main;
this.address = InetAddress.getByName(Socket.INET_ADDR);
try {
multicastSocket = new MulticastSocket(this.main.getPort());
multicastSocket.setSendBufferSize(256000);
multicastSocket.setReceiveBufferSize(256000);
multicastSocket.setReuseAddress(true);
multicastSocket.joinGroup(address);
} catch (IOException ex) {
System.out.println("There is no socket connection. Sorry.");
System.out.println(ex.toString());
}
}
示例8: createDatagramSocket
import java.net.MulticastSocket; //导入方法依赖的package包/类
public DatagramSocket createDatagramSocket(int port, InetAddress laddr)
throws SocketException {
if ( laddr.isMulticastAddress() ) {
try {
MulticastSocket ds = new MulticastSocket( port );
ds.joinGroup( laddr );
return ds;
} catch (IOException e) {
throw new SocketException( e.getLocalizedMessage() );
}
} else return new DatagramSocket(port, laddr);
}
示例9: init
import java.net.MulticastSocket; //导入方法依赖的package包/类
private void init()
throws IOException
{
ms = new MulticastSocket(advertisePort);
ms.setTimeToLive(16);
ms.joinGroup(InetAddress.getByName(groupAddress));
initialized = true;
}
示例10: AEMulticastInput
import java.net.MulticastSocket; //导入方法依赖的package包/类
/** Constructs a new AEMulticastInput thread. This Thread must be started before it will
*collect events from a source.
*@throws IOException if there is a permission problem
**/
public AEMulticastInput() throws IOException{
socket = new MulticastSocket(AENetworkInterfaceConstants.STREAM_PORT);
address = InetAddress.getByName(AENetworkInterfaceConstants.MULTICAST_INETADDR);
socket.joinGroup(address);
setName("AEMulticastInput");
}
示例11: start
import java.net.MulticastSocket; //导入方法依赖的package包/类
/**
* Prepare for the beginning of active use of the public methods of this
* component. This method should be called after <code>configure()</code>,
* and before any of the public methods of the component are utilized.
*
* @exception LifecycleException if this component detects a fatal error
* that prevents this component from being used
*/
public void start() throws LifecycleException {
// Validate and update our current component state
if (started)
throw new LifecycleException(sm.getString("standardCluster.alreadyStarted"));
try {
multicastSocket = new MulticastSocket(multicastPort);
if(multicastSocket != null && multicastAddress != null) {
multicastSocket.joinGroup(multicastAddress);
clusterSender = getClusterSender(getName());
clusterReceiver = getClusterReceiver(getName());
localClusterMember = new ClusterMemberInfo();
localClusterMember.setClusterName(getClusterName());
localClusterMember.setHostName(null);
localClusterMember.setClusterInfo(getInfo());
clusterSender.send(localClusterMember);
if (debug > 1)
log(sm.getString("standardCluster.joinGroup",
multicastAddress));
} else {
log(sm.getString("standardCluster.socketOrAddressNull"));
}
} catch (IOException e) {
log(sm.getString("standardCluster.joinException", e.toString()));
}
lifecycle.fireLifecycleEvent(START_EVENT, null);
started = true;
// Start the background reaper thread
threadStart();
}
示例12: start
import java.net.MulticastSocket; //导入方法依赖的package包/类
@Override
public void start(CoapReceiver coapReceiver) throws IOException {
mcastSocket = new MulticastSocket(bindSocket);
mcastSocket.joinGroup(mcastGroup);
LOGGER.debug("CoAP server binds on multicast " + mcastSocket.getLocalSocketAddress());
readerThread = new Thread(() -> readingLoop(coapReceiver), "multicast-reader");
readerThread.start();
}
示例13: main
import java.net.MulticastSocket; //导入方法依赖的package包/类
/**
* @param args
* @throws UnknownHostException
*/
public static void main(String[] args) throws Exception {
InetAddress group = InetAddress.getByName("228.5.6.7");
MulticastSocket s = new MulticastSocket(6789);
byte[] arb = new byte[1024];
s.joinGroup(group);// 加入该组
while (true) {
DatagramPacket datagramPacket = new DatagramPacket(arb, arb.length);
s.receive(datagramPacket);
System.out.println(arb.length);
System.out.println(new String(arb));
}
}
示例14: DiscoveryReceiver
import java.net.MulticastSocket; //导入方法依赖的package包/类
private DiscoveryReceiver()
{
try
{
socket = new MulticastSocket(5005);
socket.joinGroup(InetAddress.getByName("224.0.0.1"));
}
catch (IOException e)
{
e.printStackTrace();
}
}
示例15: openSocket
import java.net.MulticastSocket; //导入方法依赖的package包/类
private void openSocket() throws IOException
{
closeSocket();
socket = new MulticastSocket(DISCOVERY_PORT);
socket.setTimeToLive(10);
socket.setSoTimeout(1);
socket.setInterface(Network.getPrimaryAddress());
socket.joinGroup(InetAddress.getByName(DISCOVERY_GROUP));
log.info(String.format("Joined %s on %s", DISCOVERY_GROUP, socket.getInterface()));
}