当前位置: 首页>>代码示例>>Java>>正文


Java MulticastSocket.joinGroup方法代码示例

本文整理汇总了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();
    }


}
 
开发者ID:yuvaraj119,项目名称:WifiChatSharing,代码行数:21,代码来源:MessageActivity.java

示例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
}
 
开发者ID:cleitonferreira,项目名称:LivroJavaComoProgramar10Edicao,代码行数:25,代码来源:PacketReceiver.java

示例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(); }
		}
 
开发者ID:cycronix,项目名称:cloudturbine,代码行数:18,代码来源:CTudp_SyncedWrite.java

示例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;
	}
}
 
开发者ID:javalovercn,项目名称:j2se_for_android,代码行数:31,代码来源:HCWiFiManager.java

示例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;
}
 
开发者ID:apache,项目名称:ignite,代码行数:26,代码来源:TcpDiscoveryMulticastIpFinder.java

示例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);
    }
}
 
开发者ID:offbye,项目名称:DroidDLNA,代码行数:27,代码来源:MulticastReceiverImpl.java

示例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());
    }
}
 
开发者ID:flschiavoni,项目名称:shareMySheet,代码行数:15,代码来源:Socket.java

示例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);
}
 
开发者ID:YunlongYang,项目名称:LightSIP,代码行数:14,代码来源:DefaultNetworkLayer.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:AdvertiseListener.java

示例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");
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:11,代码来源:AEMulticastInput.java

示例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();
}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:46,代码来源:StandardCluster.java

示例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();
}
 
开发者ID:ARMmbed,项目名称:java-coap,代码行数:10,代码来源:MulticastSocketTransport.java

示例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));
    }

}
 
开发者ID:tiglabs,项目名称:jsf-core,代码行数:18,代码来源:BroadCastReciever.java

示例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();
    }
}
 
开发者ID:MihaiBojescu,项目名称:Linux-notifier-Android,代码行数:13,代码来源:DiscoveryReceiver.java

示例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()));
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:11,代码来源:Discovery.java


注:本文中的java.net.MulticastSocket.joinGroup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。