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


Java MulticastSocket.setLoopbackMode方法代码示例

本文整理汇总了Java中java.net.MulticastSocket.setLoopbackMode方法的典型用法代码示例。如果您正苦于以下问题:Java MulticastSocket.setLoopbackMode方法的具体用法?Java MulticastSocket.setLoopbackMode怎么用?Java MulticastSocket.setLoopbackMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.MulticastSocket的用法示例。


在下文中一共展示了MulticastSocket.setLoopbackMode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: setLoopbackMode

import java.net.MulticastSocket; //导入方法依赖的package包/类
/**
     * 
     * @param flag true to enable loopback, fals to disable loopback
     */
    public void setLoopbackMode(boolean flag) {
        try {
            Field connField = KNXNetworkLinkIP.class.getDeclaredField("conn");
            connField.setAccessible(true);
            
//            KNXnetIPConnection conn = (KNXnetIPConnection) connField.get(this);
            KNXnetIPRouting conn = (KNXnetIPRouting) connField.get(this);
            
            if (conn instanceof KNXnetIPRouting) {
                KNXnetIPRouting knxnetiprouting = (KNXnetIPRouting) conn;
                
                Field socketField = KNXnetIPRouting.class.getSuperclass().getDeclaredField("socket");
                socketField.setAccessible(true);
                MulticastSocket socket = (MulticastSocket) socketField.get(knxnetiprouting);
                socket.setLoopbackMode(!flag); // weird inverse logic, see javadoc of MulticastSocket#setLoopbackMode
                
                Field loopbackEnabledField = KNXnetIPRouting.class.getDeclaredField("loopbackEnabled");
                loopbackEnabledField.setAccessible(true);
                loopbackEnabledField.set(knxnetiprouting, !socket.getLoopbackMode());
                Boolean loopbackEnabled = (Boolean) loopbackEnabledField.get(knxnetiprouting);
                logger.info("multicast loopback mode " + (loopbackEnabled ? "enabled" : "disabled"));
                
            }
                    
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException | SocketException ex) {
            ex.printStackTrace();
        }
    }
 
开发者ID:tuxedo0801,项目名称:slicKnx,代码行数:33,代码来源:SlicKNXNetworkLinkIP.java

示例4: createSocket

import java.net.MulticastSocket; //导入方法依赖的package包/类
protected DatagramSocket createSocket() throws IOException {
    MulticastSocket s = new MulticastSocket();
    s.setSendBufferSize(maxTraceDatagramSize);
    s.setBroadcast(broadcast);
    s.setLoopbackMode(true);
    s.setTimeToLive(timeToLive);
    return s;
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:9,代码来源:MulticastTraceBrokerPlugin.java

示例5: createCommandChannel

import java.net.MulticastSocket; //导入方法依赖的package包/类
protected CommandChannel createCommandChannel() throws IOException {
    socket = new MulticastSocket(mcastPort);
    socket.setLoopbackMode(loopBackMode);
    socket.setTimeToLive(timeToLive);

    LOG.debug("Joining multicast address: " + getMulticastAddress());
    socket.joinGroup(getMulticastAddress());
    socket.setSoTimeout((int)keepAliveInterval);

    return new CommandDatagramSocket(this, getWireFormat(), getDatagramSize(), getTargetAddress(), createDatagramHeaderMarshaller(), getSocket());
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:12,代码来源:MulticastTransport.java

示例6: createSocket

import java.net.MulticastSocket; //导入方法依赖的package包/类
/**
 * @return
 */
private boolean createSocket() {
	try {
		m_socket = new MulticastSocket(m_port);
		m_socket.setLoopbackMode(false);
	} catch (IOException e) {
		s_LOGGER.error(e.getMessage(), e);

		return false;
	}

	return true;
}
 
开发者ID:pulsarIO,项目名称:jetstream,代码行数:16,代码来源:MulticastInterfaceResolver.java

示例7: start

import java.net.MulticastSocket; //导入方法依赖的package包/类
/**
 * start the discovery agent
 * 
 * @throws Exception
 */
public void start() throws Exception {
	
    if (started.compareAndSet(false, true)) {        	
    	         	
        if (group == null || group.length() == 0) {
            throw new IOException("You must specify a group to discover");
        }
        String type = getType();
        if (!type.endsWith(".")) {
            LOG.warn("The type '" + type + "' should end with '.' to be a valid Discovery type");
            type += ".";
        }
        
        if (discoveryURI == null) {
            discoveryURI = new URI(DEFAULT_DISCOVERY_URI_STRING);
        }
        
        if (LOG.isTraceEnabled()) 
    	  	LOG.trace("start - discoveryURI = " + discoveryURI);        	  	        	  
    	  
    	  String myHost = discoveryURI.getHost();
    	  int    myPort = discoveryURI.getPort(); 
    	     
    	  if( DEFAULT_HOST_STR.equals(myHost) ) 
    	  	myHost = DEFAULT_HOST_IP;       	      	  
    	  
    	  if(myPort < 0 )
    	    myPort = DEFAULT_PORT;        	    
    	  
    	  if (LOG.isTraceEnabled()) {
    	  	LOG.trace("start - myHost = " + myHost); 
    	  	LOG.trace("start - myPort = " + myPort);   	
    	  	LOG.trace("start - group  = " + group );		       	  	
    	  	LOG.trace("start - interface  = " + mcInterface );
    	  	LOG.trace("start - network interface  = " + mcNetworkInterface );
    	  	LOG.trace("start - join network interface  = " + mcJoinNetworkInterface );
    	  }	
    	  
        this.inetAddress = InetAddress.getByName(myHost);
        this.sockAddress = new InetSocketAddress(this.inetAddress, myPort);
        mcast = new MulticastSocket(myPort);
        mcast.setLoopbackMode(loopBackMode);
        mcast.setTimeToLive(getTimeToLive());
        if (mcJoinNetworkInterface != null) {
            mcast.joinGroup(sockAddress, NetworkInterface.getByName(mcJoinNetworkInterface));
        }
        else {
        	mcast.joinGroup(inetAddress);
        }
        mcast.setSoTimeout((int)keepAliveInterval);
        if (mcInterface != null) {
            mcast.setInterface(InetAddress.getByName(mcInterface));
        }
        if (mcNetworkInterface != null) {
            mcast.setNetworkInterface(NetworkInterface.getByName(mcNetworkInterface));
        }
        runner = new Thread(this);
        runner.setName(this.toString() + ":" + runner.getName());
        runner.setDaemon(true);
        runner.start();
        doAdvertizeSelf();
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:69,代码来源:MulticastDiscoveryAgent.java


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