org.jgroups.protocols.UDP.createMulticastSocket()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(2.5k)|赞(0)|评价(0)|浏览(264)

本文整理了Java中org.jgroups.protocols.UDP.createMulticastSocket()方法的一些代码示例,展示了UDP.createMulticastSocket()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。UDP.createMulticastSocket()方法的具体详情如下:
包路径:org.jgroups.protocols.UDP
类名称:UDP
方法名:createMulticastSocket

UDP.createMulticastSocket介绍

[英]Creates a DatagramSocket when bind_port > 0. Attempts to allocate the socket with port == bind_port, and increments until it finds a valid port, or until port_range has been exceeded
[中]当绑定端口>0时创建DatagramSocket。尝试分配端口==bind_port的套接字,并递增,直到找到有效端口,或直到超过端口_范围

代码示例

代码示例来源:origin: wildfly/wildfly

  1. /**
  2. * Creates a DatagramSocket when bind_port > 0. Attempts to allocate the socket with port == bind_port, and
  3. * increments until it finds a valid port, or until port_range has been exceeded
  4. * @return DatagramSocket The newly created socket
  5. * @throws Exception
  6. */
  7. protected MulticastSocket createMulticastSocketWithBindPort() throws Exception {
  8. MulticastSocket tmp=null;
  9. // 27-6-2003 bgooren, find available port in range (start_port, start_port+port_range)
  10. int rcv_port=bind_port, max_port=bind_port + port_range;
  11. while(rcv_port <= max_port) {
  12. try {
  13. return createMulticastSocket("jgroups.udp.sock", rcv_port);
  14. }
  15. catch(SocketException | SecurityException bind_ex) { // Cannot listen on this port
  16. rcv_port++;
  17. }
  18. }
  19. // Cannot listen at all, throw an Exception
  20. if(rcv_port >= max_port + 1) // +1 due to the increment above
  21. throw new Exception("failed to open a port in range " + bind_port + '-' + max_port);
  22. return tmp;
  23. }

代码示例来源:origin: wildfly/wildfly

  1. sock=createMulticastSocketWithBindPort();
  2. else
  3. sock=createMulticastSocket("jgroups.udp.sock", 0);

代码示例来源:origin: org.jboss.eap/wildfly-client-all

  1. sock=createMulticastSocketWithBindPort();
  2. else
  3. sock=createMulticastSocket("jgroups.udp.sock", 0);

代码示例来源:origin: org.jboss.eap/wildfly-client-all

  1. /**
  2. * Creates a DatagramSocket when bind_port > 0. Attempts to allocate the socket with port == bind_port, and
  3. * increments until it finds a valid port, or until port_range has been exceeded
  4. * @return DatagramSocket The newly created socket
  5. * @throws Exception
  6. */
  7. protected MulticastSocket createMulticastSocketWithBindPort() throws Exception {
  8. MulticastSocket tmp=null;
  9. // 27-6-2003 bgooren, find available port in range (start_port, start_port+port_range)
  10. int rcv_port=bind_port, max_port=bind_port + port_range;
  11. while(rcv_port <= max_port) {
  12. try {
  13. return createMulticastSocket("jgroups.udp.sock", rcv_port);
  14. }
  15. catch(SocketException | SecurityException bind_ex) { // Cannot listen on this port
  16. rcv_port++;
  17. }
  18. }
  19. // Cannot listen at all, throw an Exception
  20. if(rcv_port >= max_port + 1) // +1 due to the increment above
  21. throw new Exception("failed to open a port in range " + bind_port + '-' + max_port);
  22. return tmp;
  23. }

相关文章