/** * Creates an instance of {@link TcpServer} that creates a server socket and listens for connections * Needs to be started next. * @param thread_factory The thread factory used to create new threads * @param socket_factory The socket factory used to create sockets * @param bind_addr The local address to bind to. If null, the address will be picked by the OS * @param srv_port The local port to bind to. If 0, the port will be picked by the OS. * @param end_port If srv_port is taken, the next port is tried, until end_port has been reached, in which case an * exception will be thrown. If srv_port == end_port, only 1 port will be tried. * @param external_addr The external address in case of NAT. Ignored if null. * @param external_port The external port on the NA. If 0, srv_port is used. * @throws Exception Thrown if the creation failed */ public TcpServer(ThreadFactory thread_factory, SocketFactory socket_factory, InetAddress bind_addr, int srv_port, int end_port, InetAddress external_addr, int external_port) throws Exception { this(thread_factory, socket_factory); // this.srv_sock=this.socket_factory.createServerSocket("jgroups.tcp.server"); // this.srv_sock.setReuseAddress(reuse_addr); // Util.bind(this.srv_sock, bind_addr, srv_port, end_port); this.srv_sock=Util.createServerSocket(this.socket_factory, "jgroups.tcp.server", bind_addr, srv_port, end_port); acceptor=factory.newThread(new Acceptor(),"TcpServer.Acceptor[" + srv_sock.getLocalPort() + "]"); local_addr=localAddress(bind_addr, srv_sock.getLocalPort(), external_addr, external_port); addConnectionListener(this); }
/** * Creates an instance of {@link TcpServer} that creates a server socket and listens for connections * Needs to be started next. * @param thread_factory The thread factory used to create new threads * @param socket_factory The socket factory used to create sockets * @param bind_addr The local address to bind to. If null, the address will be picked by the OS * @param srv_port The local port to bind to. If 0, the port will be picked by the OS. * @param end_port If srv_port is taken, the next port is tried, until end_port has been reached, in which case an * exception will be thrown. If srv_port == end_port, only 1 port will be tried. * @param external_addr The external address in case of NAT. Ignored if null. * @param external_port The external port on the NA. If 0, srv_port is used. * @throws Exception Thrown if the creation failed */ public TcpServer(ThreadFactory thread_factory, SocketFactory socket_factory, InetAddress bind_addr, int srv_port, int end_port, InetAddress external_addr, int external_port) throws Exception { this(thread_factory, socket_factory); // this.srv_sock=this.socket_factory.createServerSocket("jgroups.tcp.server"); // this.srv_sock.setReuseAddress(reuse_addr); // Util.bind(this.srv_sock, bind_addr, srv_port, end_port); this.srv_sock=Util.createServerSocket(this.socket_factory, "jgroups.tcp.server", bind_addr, srv_port, end_port); acceptor=factory.newThread(new Acceptor(),"TcpServer.Acceptor[" + srv_sock.getLocalPort() + "]"); local_addr=localAddress(bind_addr, srv_sock.getLocalPort(), external_addr, external_port); addConnectionListener(this); }