Class NetworkEngine
java.lang.Object
fr.r1r0r0.deltaengine.model.engines.NetworkEngine
- All Implemented Interfaces:
Engine,java.lang.Runnable
public final class NetworkEngine extends java.lang.Object implements Engine
Network Engine of the DeltaEngine.
Manages Client/Server paradigm between computers.
A server can handle multiple clients simultaneously.
With NetworkEngine, it is impossible to have both Server and Client instance :
you must choose what the machine will do (a Server or a Client)
-
Field Summary
-
Constructor Summary
Constructors Constructor Description NetworkEngine()Default constructor. -
Method Summary
Modifier and Type Method Description ClientcreateClient(java.lang.String ipAddress, int port)Allows to create a Client object with given address and portServercreateServer(int port)Allows to create a Server object with given port.ClientgetClient()Allows getting Client instance if it was previously created.ServergetServer()Allows getting Server instance if it was previously created.voidinit()Initialize the Engine.voidrun()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
server
-
client
-
-
Constructor Details
-
NetworkEngine
NetworkEngine()Default constructor.
-
-
Method Details
-
init
public void init()Description copied from interface:EngineInitialize the Engine. -
run
public void run()- Specified by:
runin interfacejava.lang.Runnable
-
createServer
Allows to create a Server object with given port.- Parameters:
port- server port to use- Returns:
- a newly created and running server
- Throws:
IllegalCallException- If a Server instance is already running or a Client instance is already runningjava.io.IOException- if exception occurs on server creation
-
createClient
public Client createClient(java.lang.String ipAddress, int port) throws IllegalCallException, java.io.IOExceptionAllows to create a Client object with given address and port- Parameters:
ipAddress- Server addressport- server port- Returns:
- a newly created and running client, connected to the server
- Throws:
IllegalCallException- If a Client instance is already running or a Server instance is already runningjava.io.IOException- if exception occurs on client creation
-
getServer
Allows getting Server instance if it was previously created. If Server wasn't created, it will return a null.- Returns:
- server instance if Server was created, null otherwise
-
getClient
Allows getting Client instance if it was previously created. If Client wasn't created, it will return a null.- Returns:
- client instance if Client was created, null otherwise
-