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


Java MulticastSocket.setInterface方法代码示例

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


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

import java.net.MulticastSocket; //导入方法依赖的package包/类
public RxdThread() {
  super("MultiCastManager.RxdThread." + address + "#" + port);
  setDaemon(true);
  
  bReceiving  = true;
  
  try {
    msocket = new MulticastSocket( port );
    msocket.setInterface( bindAddress );
    msocket.joinGroup(groupAddr);
    start();
    
    cfcThread = new cfcRunnerThread();
    
  } catch (IOException e) {
    log( "RxdThread.IOException:" + e.getMessage() );
  }
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:19,代码来源:MultiCastManager.java

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

示例5: Receiver

import java.net.MulticastSocket; //导入方法依赖的package包/类
Receiver(InetAddress mcast_addr, InetAddress bind_interface, int port) throws Exception {
    sock=new MulticastSocket(port);
    if(bind_interface != null)
        sock.setInterface(bind_interface);
    sock.joinGroup(mcast_addr);
    System.out.println("Socket=" + sock.getLocalAddress() + ':' + sock.getLocalPort() + ", bind interface=" +
            sock.getInterface());
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:9,代码来源:McastReceiverTest.java

示例6: start

import java.net.MulticastSocket; //导入方法依赖的package包/类
/**
 * Starts a ServerSocket and a thread with this MulticastUDPSocket 
 * as the Runnable.
 */
public void start() {
	if (runner == null) {
		try {
			LOGGER.info("Multicast service : port " + portNumber + " group "+ groupAddress );
			group = InetAddress.getByName(groupAddress);
			serverSocket = new MulticastSocket(portNumber);
			//at least under Windows with multiple network interfaces, the multicast socket
			//sometimes gets confused and doesn't receive packets. Explicitly binding
			//to the network interface of InetAddress.getLocalHost seems to resolve the problem
			serverSocket.setInterface(InetAddress.getLocalHost());

			// Joins the group
			serverSocket.joinGroup(group);
			//serverSocket.setTTL(ttl); // Deprecated
			serverSocket.setTimeToLive(ttl);

			runner = new Thread(this);
			runner.start();

		} catch (IOException ioe) {
			System.out.println("MulticastUDPSocket init error: "+ioe
					+ " on port number "+portNumber
					+ " with group address " + groupAddress);
		}
	}
}
 
开发者ID:claudiotrindade,项目名称:contexttoolkit,代码行数:31,代码来源:MulticastUDPSocket.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.setInterface方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。