private void listen ( final String iHostName , final String iHostPortRange , final String iProtocolName , Class < ? extends ONetworkProtocol > protocolClass ) { for ( int port : getPorts ( iHostPortRange ) ) { inboundAddr = new InetSocketAddress ( iHostName , port ) ; try { serverSocket = socketFactory . createServerSocket ( port , 0 , InetAddress . getByName ( iHostName ) ) ; if ( serverSocket . isBound ( ) ) { OLogManager . instance ( ) . info ( this , "Listening $ANSI{green " + iProtocolName + "} connections on $ANSI{green " + inboundAddr . getAddress ( ) . getHostAddress ( ) + ":" + inboundAddr . getPort ( ) + "} (protocol v." + protocolVersion + ", socket=" + socketFactory . getName ( ) + ")" ) ; return ; } } catch ( BindException be ) { OLogManager . instance ( ) . warn ( this , "Port %s:%d busy, trying the next available..." , iHostName , port ) ; } catch ( SocketException se ) { OLogManager . instance ( ) . error ( this , "Unable to create socket" , se ) ; throw new RuntimeException ( se ) ; } catch ( IOException ioe ) { OLogManager . instance ( ) . error ( this , "Unable to read data from an open socket" , ioe ) ; System . err . println ( "Unable to read data from an open socket." ) ; throw new RuntimeException ( ioe ) ; } } OLogManager . instance ( ) . error ( this , "Unable to listen for connections using the configured ports '%s' on host '%s'" , null , iHostPortRange , iHostName ) ; throw new OSystemException ( "Unable to listen for connections using the configured ports '%s' on host '%s'" ) ; }
Initialize a server socket for communicating with the client .