@ -54,21 +54,24 @@ import com.jme3.network.kernel.*;
* /
* /
public class SelectorKernel extends AbstractKernel
public class SelectorKernel extends AbstractKernel
{
{
private InetAddress host ;
private InetSocketAddress address ;
private int port ;
private SelectorThread thread ;
private SelectorThread thread ;
private Map < Long , NioEndpoint > endpoints = new ConcurrentHashMap < Long , NioEndpoint > ( ) ;
private Map < Long , NioEndpoint > endpoints = new ConcurrentHashMap < Long , NioEndpoint > ( ) ;
public SelectorKernel ( InetAddress host , int port )
public SelectorKernel ( InetAddress host , int port )
{
{
this . host = host ;
this ( new InetSocketAddress ( host , port ) ) ;
this . port = port ;
}
}
public SelectorKernel ( int port ) throws IOException
public SelectorKernel ( int port ) throws IOException
{
{
this ( InetAddress . getLocalHost ( ) , port ) ;
this ( new InetSocketAddress ( port ) ) ;
}
public SelectorKernel ( InetSocketAddress address )
{
this . address = address ;
}
}
protected SelectorThread createSelectorThread ( )
protected SelectorThread createSelectorThread ( )
@ -87,7 +90,7 @@ public class SelectorKernel extends AbstractKernel
thread . connect ( ) ;
thread . connect ( ) ;
thread . start ( ) ;
thread . start ( ) ;
} catch ( IOException e ) {
} catch ( IOException e ) {
throw new KernelException ( "Error hosting:" + host + " port:" + port , e ) ;
throw new KernelException ( "Error hosting:" + address , e ) ;
}
}
}
}
@ -100,7 +103,7 @@ public class SelectorKernel extends AbstractKernel
thread . close ( ) ;
thread . close ( ) ;
thread = null ;
thread = null ;
} catch ( IOException e ) {
} catch ( IOException e ) {
throw new KernelException ( "Error closing host connection:" + host + " port:" + port , e ) ;
throw new KernelException ( "Error closing host connection:" + address , e ) ;
}
}
}
}
@ -205,7 +208,7 @@ public class SelectorKernel extends AbstractKernel
public SelectorThread ( )
public SelectorThread ( )
{
{
setName ( "Selector@" + host + ":" + port ) ;
setName ( "Selector@" + address ) ;
setDaemon ( true ) ;
setDaemon ( true ) ;
}
}
@ -219,8 +222,7 @@ public class SelectorKernel extends AbstractKernel
serverChannel . configureBlocking ( false ) ;
serverChannel . configureBlocking ( false ) ;
// Bind the server socket to the specified address and port
// Bind the server socket to the specified address and port
InetSocketAddress isa = new InetSocketAddress ( host , port ) ;
serverChannel . socket ( ) . bind ( address ) ;
serverChannel . socket ( ) . bind ( isa ) ;
// Register the server socket channel, indicating an interest in
// Register the server socket channel, indicating an interest in
// accepting new connections
// accepting new connections