Class EchoServerThreaded


  • public class EchoServerThreaded
    extends java.lang.Object
    threaded server for var.sockets.tcp.echo Echo service. waits for the next client to connect, creates thread and handles connection in concurrently: sends greeting message to client, reads line by line from client and sends it back adding "echo: " in front of each line until connection is closed by client.
    Author:
    Sandro Leuchter
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  EchoServerThreaded.EchoThread
      Each connection is handled with an instance of this class.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int port
      port on which this service is currently listening on localhost
    • Constructor Summary

      Constructors 
      Constructor Description
      EchoServerThreaded​(int port)
      the only constructor for this class
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void main​(java.lang.String[] args)
      main method: entrypoint to run service
      void start()
      creates server socket on localhost:port, infinitely handles connections to clients concurrently
      • Methods inherited from class java.lang.Object

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

      • port

        private final int port
        port on which this service is currently listening on localhost
    • Constructor Detail

      • EchoServerThreaded

        public EchoServerThreaded​(int port)
        the only constructor for this class
        Parameters:
        port - port on which this service will be listening on localhost
    • Method Detail

      • start

        public void start()
        creates server socket on localhost:port, infinitely handles connections to clients concurrently
      • main

        public static void main​(java.lang.String[] args)
        main method: entrypoint to run service
        Parameters:
        args - args[0] must be the port number of the server (int); rest of args is ignored