Added the rest of the game name and version stuff... still

doesn't validate with it but at least the client and server
can be setup now.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7039 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
PSp..om 14 years ago
parent dda3e4c2a0
commit 5faa1f08fe
  1. 13
      engine/src/networking/com/jme3/network/Client.java
  2. 55
      engine/src/networking/com/jme3/network/Network.java
  3. 15
      engine/src/networking/com/jme3/network/base/DefaultClient.java

@ -61,6 +61,19 @@ public interface Client extends MessageConnection
*/ */
public int getId(); public int getId();
/**
* Returns the 'game name' for servers to which this client should be able
* to connect. This should match the 'game name' set on the server or this
* client will be turned away.
*/
public String getGameName();
/**
* Returns the game-specific version of the server this client should
* be able to connect to.
*/
public int getVersion();
/** /**
* Sends a message to the server. * Sends a message to the server.
*/ */

@ -51,6 +51,9 @@ import com.jme3.network.kernel.udp.UdpKernel;
*/ */
public class Network public class Network
{ {
public static final String DEFAULT_GAME_NAME = "Unnamed jME3 Game";
public static final int DEFAULT_VERSION = 42;
/** /**
* Creates a Server that will utilize both reliable and fast * Creates a Server that will utilize both reliable and fast
* transports to communicate with clients. The specified port * transports to communicate with clients. The specified port
@ -58,7 +61,7 @@ public class Network
*/ */
public static Server createServer( int port ) throws IOException public static Server createServer( int port ) throws IOException
{ {
return createServer( "Unnamed Game", 42, port, port ); return createServer( DEFAULT_GAME_NAME, DEFAULT_VERSION, port, port );
} }
/** /**
@ -68,7 +71,7 @@ public class Network
*/ */
public static Server createServer( int tcpPort, int udpPort ) throws IOException public static Server createServer( int tcpPort, int udpPort ) throws IOException
{ {
return createServer( "Unnamed Game", 42, tcpPort, udpPort ); return createServer( DEFAULT_GAME_NAME, DEFAULT_VERSION, tcpPort, udpPort );
} }
/** /**
@ -87,7 +90,6 @@ public class Network
public static Server createServer( String gameName, int version, int tcpPort, int udpPort ) throws IOException public static Server createServer( String gameName, int version, int tcpPort, int udpPort ) throws IOException
{ {
UdpKernel fast = new UdpKernel(udpPort); UdpKernel fast = new UdpKernel(udpPort);
//UdpKernel fast = new UdpKernel( InetAddress.getByName("localhost"), udpPort);
SelectorKernel reliable = new SelectorKernel(tcpPort); SelectorKernel reliable = new SelectorKernel(tcpPort);
return new DefaultServer( gameName, version, reliable, fast ); return new DefaultServer( gameName, version, reliable, fast );
@ -98,7 +100,7 @@ public class Network
*/ */
public static NetworkClient createClient() public static NetworkClient createClient()
{ {
return createClient( "Unnamed Game", 42 ); return createClient( DEFAULT_GAME_NAME, DEFAULT_VERSION );
} }
/** /**
@ -114,48 +116,61 @@ public class Network
/** /**
* Creates a Client that communicates with the specified host and port * Creates a Client that communicates with the specified host and port
* using both reliable and fast transports. The localUdpPort specifies the * using both reliable and fast transports. The localUdpPort specifies the
* local port to use for listening for incoming 'fast' UDP messages. * local port to use for listening for incoming 'fast' UDP messages from the
* server. This port is different than the host port in case the client
* and server are run on the same machine.
*/ */
public static Client connectToServer( String host, int hostPort, int localUdpPort ) throws IOException public static Client connectToServer( String host, int hostPort, int localUdpPort ) throws IOException
{ {
return connectToServer( InetAddress.getByName(host), hostPort, hostPort, localUdpPort ); return connectToServer( DEFAULT_GAME_NAME, DEFAULT_VERSION, host, hostPort, hostPort, localUdpPort );
} }
/** /**
* Creates a Client that communicates with the specified host and port * Creates a Client that communicates with the specified host and port
* using both reliable and fast transports. The localUdpPort specifies the * using both reliable and fast transports. The localUdpPort specifies the
* local port to use for listening for incoming 'fast' UDP messages. * local port to use for listening for incoming 'fast' UDP messages from the
* server. This port is different than the host port in case the client
* and server are run on the same machine.
*/ */
public static Client connectToServer( String host, int hostPort, int remoteUdpPort, public static Client connectToServer( String host, int hostPort, int remoteUdpPort,
int localUdpPort ) throws IOException int localUdpPort ) throws IOException
{ {
return connectToServer( InetAddress.getByName(host), hostPort, remoteUdpPort, localUdpPort ); return connectToServer( DEFAULT_GAME_NAME, DEFAULT_VERSION, host, hostPort, remoteUdpPort,
localUdpPort );
} }
/** /**
* Creates a Client that communicates with the specified address and port * Creates a Client that communicates with the specified host and port
* using both reliable and fast transports. The localUdpPort specifies the * using both reliable and fast transports. The localUdpPort specifies the
* local port to use for listening for incoming 'fast' messages. * local port to use for listening for incoming 'fast' UDP messages from the
* server. This port is different than the host port in case the client
* and server are run on the same machine.
*/ */
public static Client connectToServer( InetAddress address, int port, int localUdpPort ) throws IOException public static Client connectToServer( String gameName, int version,
String host, int hostPort, int localUdpPort ) throws IOException
{ {
return connectToServer( address, port, port, localUdpPort ); return connectToServer( host, hostPort, hostPort, localUdpPort );
} }
/** /**
* Creates a Client that communicates with the specified address and port * Creates a Client that communicates with the specified host and port
* using both reliable and fast transports. The localUdpPort specifies the * using both reliable and fast transports. The localUdpPort specifies the
* local port to use for listening for incoming 'fast' messages. * local port to use for listening for incoming 'fast' UDP messages from the
* server. This port is different than the host port in case the client
* and server are run on the same machine.
*/ */
public static Client connectToServer( InetAddress address, int port, int remoteUdpPort, public static Client connectToServer( String gameName, int version,
String host, int hostPort, int remoteUdpPort,
int localUdpPort ) throws IOException int localUdpPort ) throws IOException
{ {
UdpConnector fast = new UdpConnector( localUdpPort, address, port ); InetAddress remoteAddress = InetAddress.getByName(host);
SocketConnector reliable = new SocketConnector( address, port ); UdpConnector fast = new UdpConnector( localUdpPort, remoteAddress, hostPort );
SocketConnector reliable = new SocketConnector( remoteAddress, hostPort );
return new DefaultClient( reliable, fast ); return new DefaultClient( gameName, version, reliable, fast );
} }
protected static class NetworkClientImpl extends DefaultClient implements NetworkClient protected static class NetworkClientImpl extends DefaultClient implements NetworkClient
{ {
public NetworkClientImpl(String gameName, int version) public NetworkClientImpl(String gameName, int version)

@ -73,8 +73,9 @@ public class DefaultClient implements Client
this.version = version; this.version = version;
} }
public DefaultClient( Connector reliable, Connector fast ) public DefaultClient( String gameName, int version, Connector reliable, Connector fast )
{ {
this( gameName, version );
setConnectors( reliable, fast ); setConnectors( reliable, fast );
} }
@ -100,7 +101,7 @@ public class DefaultClient implements Client
if( !isRunning ) if( !isRunning )
throw new IllegalStateException( "Client is not started." ); throw new IllegalStateException( "Client is not started." );
} }
public void start() public void start()
{ {
if( isRunning ) if( isRunning )
@ -159,6 +160,16 @@ public class DefaultClient implements Client
return id; return id;
} }
public String getGameName()
{
return gameName;
}
public int getVersion()
{
return version;
}
public void send( Message message ) public void send( Message message )
{ {
checkRunning(); checkRunning();

Loading…
Cancel
Save