Class Network
java.lang.Object
com.jme3.network.Network
The main service provider for conveniently creating
server and client instances.
- Author:
- Paul Speed
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classClient implementation used by the convenience factory methods. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault game name used by the convenience factory methods.static final intDefault protocol version used by the convenience factory methods. -
Method Summary
Modifier and TypeMethodDescriptionstatic ClientconnectToServer(String host, int hostPort) Creates a Client that communicates with the specified host and port using both reliable and fast transports.static ClientconnectToServer(String host, int hostPort, int remoteUdpPort) Creates a Client that communicates with the specified host and separate TCP and UDP ports using both reliable and fast transports.static ClientconnectToServer(String gameName, int version, String host, int hostPort) Creates a Client that communicates with the specified host and port using both reliable and fast transports.static ClientconnectToServer(String gameName, int version, String host, int hostPort, int remoteUdpPort) Creates a Client that communicates with the specified host and separate TCP and UDP ports using both reliable and fast transports.static NetworkClientCreates a client that can be connected at a later time.static NetworkClientcreateClient(String gameName, int version) Creates a client that can be connected at a later time.static ServercreateServer(int port) Creates a Server that will utilize both reliable and fast transports to communicate with clients.static ServercreateServer(int tcpPort, int udpPort) Creates a Server that will utilize both reliable and fast transports to communicate with clients.static ServercreateServer(String gameName, int version, int tcpPort, int udpPort) Creates a named and versioned Server that will utilize both reliable and fast transports to communicate with clients.
-
Field Details
-
DEFAULT_GAME_NAME
Default game name used by the convenience factory methods.- See Also:
-
DEFAULT_VERSION
public static final int DEFAULT_VERSIONDefault protocol version used by the convenience factory methods.- See Also:
-
-
Method Details
-
createServer
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.- Parameters:
port- the port used for both TCP and UDP communication- Returns:
- the created server
- Throws:
IOException- if the server cannot be created
-
createServer
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.- Parameters:
tcpPort- the TCP listening portudpPort- the UDP listening port- Returns:
- the created server
- Throws:
IOException- if the server cannot be created
-
createServer
public static Server createServer(String gameName, int version, int tcpPort, int udpPort) throws IOException Creates a named and versioned 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.- Parameters:
gameName- This is the name that identifies the game. Connecting clients must use this name or be turned away.version- This is a game-specific version that helps detect when out-of-date clients have connected to an incompatible server.tcpPort- The port upon which the TCP hosting will listen for new connections.udpPort- The port upon which the UDP hosting will listen for new 'fast' UDP messages. Set to -1 if 'fast' traffic should go over TCP. This will completely disable UDP traffic for this server.- Returns:
- the created server
- Throws:
IOException- if the server cannot be created
-
createClient
Creates a client that can be connected at a later time.- Returns:
- the created client
-
createClient
Creates a client that can be connected at a later time. The specified game name and version must match the server or the client will be turned away.- Parameters:
gameName- the expected game nameversion- the expected protocol version- Returns:
- the created client
-
connectToServer
Creates a Client that communicates with the specified host and port using both reliable and fast transports.- Parameters:
host- the remote host name or addresshostPort- the remote TCP and UDP port- Returns:
- the connected client
- Throws:
IOException- if the client cannot connect
-
connectToServer
public static Client connectToServer(String host, int hostPort, int remoteUdpPort) throws IOException Creates a Client that communicates with the specified host and separate TCP and UDP ports using both reliable and fast transports.- Parameters:
host- the remote host name or addresshostPort- the remote TCP portremoteUdpPort- the remote UDP port- Returns:
- the connected client
- Throws:
IOException- if the client cannot connect
-
connectToServer
public static Client connectToServer(String gameName, int version, String host, int hostPort) throws IOException Creates a Client that communicates with the specified host and port using both reliable and fast transports.- Parameters:
gameName- the expected game nameversion- the expected protocol versionhost- the remote host name or addresshostPort- the remote TCP and UDP port- Returns:
- the connected client
- Throws:
IOException- if the client cannot connect
-
connectToServer
public static Client connectToServer(String gameName, int version, String host, int hostPort, int remoteUdpPort) throws IOException Creates a Client that communicates with the specified host and separate TCP and UDP ports using both reliable and fast transports.- Parameters:
gameName- This is the name that identifies the game. This must match the target server's name or this client will be turned away.version- This is a game-specific version that helps detect when out-of-date clients have connected to an incompatible server. This must match the server's version of this client will be turned away.host- the remote host name or addresshostPort- The remote TCP port on the server to which this client should send reliable messages.remoteUdpPort- The remote UDP port on the server to which this client should send 'fast'/unreliable messages. Set to -1 if 'fast' traffic should go over TCP. This will completely disable UDP traffic for this client.- Returns:
- the connected client
- Throws:
IOException- if the client cannot connect
-