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


Java MulticastSocket.close方法代码示例

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


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

示例1: pingListener

import java.net.MulticastSocket; //导入方法依赖的package包/类
protected void pingListener() {
    try {
        byte[] buf = new byte[256];
        String testData = "M-SEARCH * HTTP/1.1\nHOST: " + Configuration.UPNP_MULTICAST_ADDRESS + ":" + Configuration.UPNP_DISCOVERY_PORT + "ST: urn:schemas-upnp-org:device:CloudProxy:1\nMAN: \"ssdp:discover\"\nMX: 3";
        buf = testData.getBytes();
        MulticastSocket socket = new MulticastSocket(Configuration.UPNP_DISCOVERY_PORT);

        InetAddress group = InetAddress.getByName(Configuration.UPNP_MULTICAST_ADDRESS);
        DatagramPacket packet;
        packet = new DatagramPacket(buf, buf.length, group, Configuration.UPNP_DISCOVERY_PORT);
        socket.send(packet);

        socket.close();
    }
    catch (IOException e) {
    	log.warn("Error pinging listener. " + e.getMessage());
    }
}
 
开发者ID:bwssytems,项目名称:ha-bridge,代码行数:19,代码来源:SystemControl.java

示例2: sendTextMessageThroughUdp

import java.net.MulticastSocket; //导入方法依赖的package包/类
@Test
public void sendTextMessageThroughUdp() throws Exception {
    // replace existing implementation for testing purposes
    _testKit.removeService("DefaultGreetingService");
    final MockHandler greetingService = _testKit.registerInOnlyService("DefaultGreetingService");

    MulticastSocket clientSocket = new MulticastSocket();
    InetAddress group = InetAddress.getByName("localhost");
    byte[] datagramBody = PAYLOAD.getBytes(Charset.defaultCharset());
    DatagramPacket packet = new DatagramPacket(datagramBody, 0, datagramBody.length, group, 3940);
    clientSocket.send(packet);

    // sleep a bit to receive message on camel side
    clientSocket.close();

    greetingService.waitForOKMessage();
    final LinkedBlockingQueue<Exchange> recievedMessages = greetingService.getMessages();
    assertThat(recievedMessages, is(notNullValue()));
    final Exchange recievedExchange = recievedMessages.iterator().next();
    String content = recievedExchange.getMessage().getContent(String.class);
    // the receive content is trimmed because extra bytes appended to frame by receiver
    assertThat(PAYLOAD, is(equalTo(content.trim())));
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:24,代码来源:CamelNettyBindingTest.java

示例3: safeClose

import java.net.MulticastSocket; //导入方法依赖的package包/类
private void safeClose(final MulticastSocket multicastSocket) {
    try {
        if (multicastSocket != null) {
            multicastSocket.close();
        }
    } catch (final RuntimeException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Ignored exception while safe-closing multicast socket.", e);
        }
    }
}
 
开发者ID:alexmaret,项目名称:openhab-binding-zmote,代码行数:12,代码来源:ZMoteDiscoveryService.java

示例4: closeMulticastSocket

import java.net.MulticastSocket; //导入方法依赖的package包/类
void closeMulticastSocket() {
    if(mcast_recv_sock != null) {
        try {
            if(mcast_addr != null) {
                mcast_recv_sock.leaveGroup(mcast_addr.getIpAddress());
            }
            mcast_recv_sock.close(); // this will cause the mcast receiver thread to break out of its loop
            //mcast_recv_sock=null;
            if(log.isDebugEnabled()) log.debug("multicast receive socket closed");
        }
        catch(IOException ex) {
        }
        mcast_addr=null;
    }

    if(mcast_send_sock != null) {
        mcast_send_sock.close();
        //mcast_send_sock=null;
        if(log.isDebugEnabled()) log.debug("multicast send socket closed");
    }
    if(mcast_send_sockets != null) {
        MulticastSocket s;
        for(int i=0; i < mcast_send_sockets.length; i++) {
            s=mcast_send_sockets[i];
            s.close();
            if(log.isDebugEnabled()) log.debug("multicast send socket " + s + " closed");
        }
        mcast_send_sockets=null;
    }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:31,代码来源:UDP.java

示例5: emergencyClose

import java.net.MulticastSocket; //导入方法依赖的package包/类
/**
 * Closes the datagram socket, any multicast receive sockets,
 * and interrupts their threads.
 */
@Override // GemStoneAddition  
public void emergencyClose() {
  closeSocket();

  MulticastSocket ms = mcast_recv_sock;
  if (ms != null) {
    ms.close();
  }
  ms = mcast_send_sock;
  if (ms != null) {
    ms.close();
  }
  if (mcast_send_sockets != null) {
    for (int i = 0; i < mcast_send_sockets.length; i ++) {
      ms = mcast_send_sockets[i];
      if (ms != null) {
        ms.close();
      }
    }
  }
  
  Thread thr = mcast_receiver;
  if (thr != null) {
    thr.interrupt();
  }
  UcastReceiver ur = ucast_receiver;
  if (ur != null) {
    thr = ur.thread;
    if (thr != null) {
      thr.interrupt();
      }
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:38,代码来源:UDP.java

示例6: emergencyClose

import java.net.MulticastSocket; //导入方法依赖的package包/类
/**
 * Closes the diagnostic handler, if it is open
 */
public void emergencyClose() {
  DiagnosticsHandler ds = diag_handler;
  if (ds != null) {
    MulticastSocket ms = ds.diag_sock;
    if (ms != null) {
      ms.close();
    }
    Thread thr = ds.t;
    if (thr != null) {
      thr.interrupt();
    }
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:17,代码来源:TP.java

示例7: main

import java.net.MulticastSocket; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) throws Exception{
	int port=9527;
	int aport=9528;
	InetAddress groupAddress=InetAddress.getByName("224.1.1.1");
	
	MulticastSocket server=new MulticastSocket(port);
	server.joinGroup(groupAddress);
	
	MulticastSocket client=new MulticastSocket();
	client.joinGroup(groupAddress);
	
	byte[] buffer=new byte[65507];
	DatagramPacket packet=new DatagramPacket(buffer,buffer.length);
	while(true){
		server.receive(packet);
		String line=new String(packet.getData(),0,packet.getLength(),"UTF-8");
		if("quit".equalsIgnoreCase(line.trim())){
			server.close();
			System.exit(0);
		}
		else{
			System.out.println("Message from client: "+ line);
			packet.setLength(buffer.length);
			String response="Server response��"+line;
			byte[] datas=response.getBytes("UTF-8");
			DatagramPacket responsePacket=new DatagramPacket(datas,datas.length,groupAddress,aport);
			client.send(responsePacket);
			Thread.sleep(100);
		}
	}
}
 
开发者ID:java-scott,项目名称:java-project,代码行数:35,代码来源:Server.java

示例8: main

import java.net.MulticastSocket; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) throws Exception{
	int port=9527;
	int aport=9528;
	
	InetAddress groupAddress=InetAddress.getByName("224.1.1.1");
	
	MulticastSocket serverSocket=new MulticastSocket(aport);
	serverSocket.joinGroup(groupAddress);
	byte[] buffer=new byte[65507];
	DatagramPacket receivePacket=new DatagramPacket(buffer,buffer.length);
	MulticastSocket socket=new MulticastSocket();
	socket.joinGroup(groupAddress);
	BufferedReader systemIn=new BufferedReader(new InputStreamReader(System.in));
	boolean flag=true;
	while(flag){
		String command=systemIn.readLine();
		byte[] datas=command.getBytes("UTF-8");
		DatagramPacket packet=new DatagramPacket(datas,datas.length,groupAddress,port);
		socket.send(packet);
		if(command==null || "quit".equalsIgnoreCase(command.trim())){
			flag=false;
			System.out.println("Client quit!");
			socket.leaveGroup(groupAddress);
			socket.close();
			serverSocket.leaveGroup(groupAddress);
			serverSocket.close();
			continue;
		}
		serverSocket.receive(receivePacket);
		String receiveResponse=new String(receivePacket.getData(),0,receivePacket.getLength(),"UTF-8");
		System.out.println(receiveResponse);
	}
}
 
开发者ID:java-scott,项目名称:java-project,代码行数:37,代码来源:Client.java

示例9: closeHard

import java.net.MulticastSocket; //导入方法依赖的package包/类
public static void closeHard(final MulticastSocket multicastSocket) {

      if (multicastSocket == null) {
         return;
      }
      try {
         multicastSocket.close();
      } catch (final Exception e) {
         ignoreExpectedException(e);
      }
   }
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:12,代码来源:IOUtils.java

示例10: OioDatagramChannel

import java.net.MulticastSocket; //导入方法依赖的package包/类
/**
 * Create a new instance from the given {@link MulticastSocket}.
 *
 * @param socket    the {@link MulticastSocket} which is used by this instance
 */
public OioDatagramChannel(MulticastSocket socket) {
    super(null);

    boolean success = false;
    try {
        socket.setSoTimeout(SO_TIMEOUT);
        socket.setBroadcast(false);
        success = true;
    } catch (SocketException e) {
        throw new ChannelException(
                "Failed to configure the datagram socket timeout.", e);
    } finally {
        if (!success) {
            socket.close();
        }
    }

    this.socket = socket;
    config = new DefaultDatagramChannelConfig(this, socket);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:26,代码来源:OioDatagramChannel.java

示例11: sendNotify

import java.net.MulticastSocket; //导入方法依赖的package包/类
private static void sendNotify(String notifyMessage) throws IOException {
    MulticastSocket socket = new MulticastSocket(null);
    try {
    	socket.bind(new InetSocketAddress(InetAddress.getLocalHost().getCanonicalHostName(), PORT));
        byte[] data = notifyMessage.toString().getBytes();
        socket.send(new DatagramPacket(data, data.length, new InetSocketAddress(getBroadCastAddress(), PORT)));
    } catch (IOException e) {
        throw e;
    } finally {
        socket.disconnect();
        socket.close();
    }
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:14,代码来源:SsdpDiscovery.java

示例12: destoryReceiver

import java.net.MulticastSocket; //导入方法依赖的package包/类
public static void destoryReceiver(MulticastSocket s) throws UnknownHostException, IOException {
    if (s == null)
        return;

    // Leave the multicast group and close the socket
    s.leaveGroup(InetAddress.getByName(GROUP));
    s.close();
}
 
开发者ID:phishman3579,项目名称:Bitcoin,代码行数:9,代码来源:Multicast.java

示例13: destroySender

import java.net.MulticastSocket; //导入方法依赖的package包/类
public static void destroySender(MulticastSocket s) throws IOException {
    if (s == null)
        return;

    // When we have finished sending data close the socket
    s.close();
}
 
开发者ID:phishman3579,项目名称:Bitcoin,代码行数:8,代码来源:Multicast.java

示例14: run

import java.net.MulticastSocket; //导入方法依赖的package包/类
@Override
public void run() {
	super.run();
	run = true;
	while (run) {
		System.out.println("Waiting for UDP Events");
		try {
			MulticastSocket socket = new MulticastSocket(5000);
			InetAddress group = InetAddress.getByName("239.1.1.1");
			socket.joinGroup(group);

			DatagramPacket packet;
			for (int i = 0; i < 5; i++) {
				byte[] buf = new byte[4096];
				packet = new DatagramPacket(buf, buf.length);
				socket.receive(packet);

				String received = new String(packet.getData());
				System.out.println("Got message: " + received);
				ActorMessage message = new ObjectMapper().readValue(received, ActorMessage.class);

				ProcessRunner processRunner = new ProcessRunner(message);
				processRunner.run();
			}

			socket.leaveGroup(group);
			socket.close();

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
 
开发者ID:comdata,项目名称:HomeAutomation,代码行数:36,代码来源:StandAloneActor.java

示例15: testUDPUnsecure

import java.net.MulticastSocket; //导入方法依赖的package包/类
@Test
public void testUDPUnsecure() throws Exception {
    MulticastSocket clientSocket = new MulticastSocket();
    InetAddress group = InetAddress.getByName("localhost");

    byte[] datagramBody = getClass().getName().getBytes();
    DatagramPacket packet = new DatagramPacket(datagramBody, 0, datagramBody.length, group, 3940);
    clientSocket.send(packet);

    Thread.sleep(1000);
    clientSocket.close();
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:13,代码来源:CamelNettyBindingQuickstartTest.java


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