/** * 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 * @return DatagramSocket The newly created socket * @throws Exception */ protected MulticastSocket createMulticastSocketWithBindPort() throws Exception { MulticastSocket tmp=null; // 27-6-2003 bgooren, find available port in range (start_port, start_port+port_range) int rcv_port=bind_port, max_port=bind_port + port_range; while(rcv_port <= max_port) { try { return createMulticastSocket("jgroups.udp.sock", rcv_port); } catch(SocketException | SecurityException bind_ex) { // Cannot listen on this port rcv_port++; } } // Cannot listen at all, throw an Exception if(rcv_port >= max_port + 1) // +1 due to the increment above throw new Exception("failed to open a port in range " + bind_port + '-' + max_port); return tmp; }
sock=createMulticastSocketWithBindPort(); else sock=createMulticastSocket("jgroups.udp.sock", 0);
sock=createMulticastSocketWithBindPort(); else sock=createMulticastSocket("jgroups.udp.sock", 0);
/** * 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 * @return DatagramSocket The newly created socket * @throws Exception */ protected MulticastSocket createMulticastSocketWithBindPort() throws Exception { MulticastSocket tmp=null; // 27-6-2003 bgooren, find available port in range (start_port, start_port+port_range) int rcv_port=bind_port, max_port=bind_port + port_range; while(rcv_port <= max_port) { try { return createMulticastSocket("jgroups.udp.sock", rcv_port); } catch(SocketException | SecurityException bind_ex) { // Cannot listen on this port rcv_port++; } } // Cannot listen at all, throw an Exception if(rcv_port >= max_port + 1) // +1 due to the increment above throw new Exception("failed to open a port in range " + bind_port + '-' + max_port); return tmp; }