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

    Fields
    Modifier and Type Field Description
    private Client client  
    private Server server  
  • Constructor Summary

    Constructors
    Constructor Description
    NetworkEngine()
    Default constructor.
  • Method Summary

    Modifier and Type Method Description
    Client createClient​(java.lang.String ipAddress, int port)
    Allows to create a Client object with given address and port
    Server createServer​(int port)
    Allows to create a Server object with given port.
    Client getClient()
    Allows getting Client instance if it was previously created.
    Server getServer()
    Allows getting Server instance if it was previously created.
    void init()
    Initialize the Engine.
    void run()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • server

      private Server server
    • client

      private Client client
  • Constructor Details

    • NetworkEngine

      NetworkEngine()
      Default constructor.
  • Method Details

    • init

      public void init()
      Description copied from interface: Engine
      Initialize the Engine.
      Specified by:
      init in interface Engine
    • run

      public void run()
      Specified by:
      run in interface java.lang.Runnable
    • createServer

      public Server createServer​(int port) throws IllegalCallException, java.io.IOException
      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 running
      java.io.IOException - if exception occurs on server creation
    • createClient

      public Client createClient​(java.lang.String ipAddress, int port) throws IllegalCallException, java.io.IOException
      Allows to create a Client object with given address and port
      Parameters:
      ipAddress - Server address
      port - 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 running
      java.io.IOException - if exception occurs on client creation
    • getServer

      public Server 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

      public Client 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