Class ServerThread

  • All Implemented Interfaces:
    java.lang.Runnable

    public class ServerThread
    extends java.lang.Thread
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Constructor Summary

      Constructors 
      Constructor Description
      ServerThread​(Server serverx, java.net.Socket socketx)
      Constructor of the server thread
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      closes the socket of the server
      long getLastContact()
      "getter" for the last contact of the server
      java.lang.String getMyName()
      "getter" for the nickname of the player
      Server getServer()
      "getter" for the server
      java.net.Socket getSocket()
      "getter" for the socket
      int getThreadId()
      "getter" for the id of the thread
      void open()
      opens the Input- and OutputStream for the socket
      void run()
      run method listens to the input stream, processes the data that it receives
      void send​(IMessage msg)
      method of the sending of a message
      void setMyName​(java.lang.String myName)
      "setter" for the nickname of the player
      void updateLastContact()
      updates the last contact of the server in milliseconds
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ServerThread

        public ServerThread​(Server serverx,
                            java.net.Socket socketx)
        Constructor of the server thread
        Parameters:
        serverx - the server
        socketx - the socket of the server
    • Method Detail

      • run

        public void run()
        run method listens to the input stream, processes the data that it receives
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
      • open

        public void open()
                  throws java.io.IOException
        opens the Input- and OutputStream for the socket
        Throws:
        java.io.IOException - exception for wrong input
      • close

        public void close()
                   throws java.io.IOException
        closes the socket of the server
        Throws:
        java.io.IOException - exception if socket isnt closed correctly
      • send

        public void send​(IMessage msg)
        method of the sending of a message
        Parameters:
        msg - - the message
      • getServer

        public Server getServer()
        "getter" for the server
        Returns:
        - the server
      • getThreadId

        public int getThreadId()
        "getter" for the id of the thread
        Returns:
        - the id of the thread
      • getMyName

        public java.lang.String getMyName()
        "getter" for the nickname of the player
        Returns:
        - nickname of the player
      • setMyName

        public void setMyName​(java.lang.String myName)
        "setter" for the nickname of the player
        Parameters:
        myName - - nickname of the player
      • getLastContact

        public long getLastContact()
        "getter" for the last contact of the server
        Returns:
        - last contact of the server (the time)
      • updateLastContact

        public void updateLastContact()
        updates the last contact of the server in milliseconds
      • getSocket

        public java.net.Socket getSocket()
        "getter" for the socket
        Returns:
        - the socket