Better address binding.
Deprecated the methods on the old Message class that are truly dangerous in the new version since they always return null. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7016 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
24b65c4914
commit
d1c8626419
@ -58,10 +58,20 @@ public class Network
|
|||||||
*/
|
*/
|
||||||
public static Server createServer( int port ) throws IOException
|
public static Server createServer( int port ) throws IOException
|
||||||
{
|
{
|
||||||
InetAddress local = InetAddress.getLocalHost();
|
return createServer( port, port );
|
||||||
|
}
|
||||||
|
|
||||||
UdpKernel fast = new UdpKernel(local, port);
|
/**
|
||||||
SelectorKernel reliable = new SelectorKernel(local,port);
|
* Creates a Server that will utilize both reliable and fast
|
||||||
|
* transports to communicate with clients. The specified port
|
||||||
|
* will be used for both TCP and UDP communication.
|
||||||
|
*/
|
||||||
|
public static Server createServer( int tcpPort, int udpPort ) throws IOException
|
||||||
|
{
|
||||||
|
//InetAddress local = InetAddress.getLocalHost();
|
||||||
|
|
||||||
|
UdpKernel fast = new UdpKernel(udpPort);
|
||||||
|
SelectorKernel reliable = new SelectorKernel(tcpPort);
|
||||||
|
|
||||||
return new DefaultServer( reliable, fast );
|
return new DefaultServer( reliable, fast );
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -49,8 +49,7 @@ import com.jme3.network.kernel.*;
|
|||||||
*/
|
*/
|
||||||
public class UdpKernel extends AbstractKernel
|
public class UdpKernel extends AbstractKernel
|
||||||
{
|
{
|
||||||
private InetAddress host;
|
private InetSocketAddress address;
|
||||||
private int port;
|
|
||||||
private HostThread thread;
|
private HostThread thread;
|
||||||
|
|
||||||
// The nature of UDP means that even through a firewall,
|
// The nature of UDP means that even through a firewall,
|
||||||
@ -60,13 +59,17 @@ public class UdpKernel extends AbstractKernel
|
|||||||
|
|
||||||
public UdpKernel( InetAddress host, int port )
|
public UdpKernel( InetAddress host, int port )
|
||||||
{
|
{
|
||||||
this.host = host;
|
this( new InetSocketAddress(host, port) );
|
||||||
this.port = port;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UdpKernel( int port ) throws IOException
|
public UdpKernel( int port ) throws IOException
|
||||||
{
|
{
|
||||||
this( InetAddress.getLocalHost(), port );
|
this( new InetSocketAddress(port) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public UdpKernel( InetSocketAddress address )
|
||||||
|
{
|
||||||
|
this.address = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HostThread createHostThread()
|
protected HostThread createHostThread()
|
||||||
@ -85,7 +88,7 @@ public class UdpKernel 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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +101,7 @@ public class UdpKernel 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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +173,7 @@ public class UdpKernel extends AbstractKernel
|
|||||||
|
|
||||||
public HostThread()
|
public HostThread()
|
||||||
{
|
{
|
||||||
setName( "UDP Host@" + host + ":" + port );
|
setName( "UDP Host@" + address );
|
||||||
setDaemon(true);
|
setDaemon(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +184,7 @@ public class UdpKernel extends AbstractKernel
|
|||||||
|
|
||||||
public void connect() throws IOException
|
public void connect() throws IOException
|
||||||
{
|
{
|
||||||
socket = new DatagramSocket( port, host );
|
socket = new DatagramSocket( address );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException, InterruptedException
|
public void close() throws IOException, InterruptedException
|
||||||
|
@ -65,18 +65,22 @@ public class Message implements com.jme3.network.Message {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public Client getClient() {
|
public Client getClient() {
|
||||||
return connector;
|
return connector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public void setClient(Client connector) {
|
public void setClient(Client connector) {
|
||||||
this.connector = connector;
|
this.connector = connector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public Connection getConnection() {
|
public Connection getConnection() {
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public void setConnection(Connection connection) {
|
public void setConnection(Connection connection) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user