Class FileServerIterativ


  • public class FileServerIterativ
    extends java.lang.Object
    iterative server for var.sockets.tcp.filer File service. waits for the next client to connect. Upon connection sends a manually defined file back to client. closes the connection directly afterwards and handles then next client
    Author:
    Sandro Leuchter
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int backlog
      requested maximum length of the queue of incoming connections.
      private static java.lang.String FILE
      path to file which will be sent to clients; relative to current working directory (e.g.
      private int port
      port on which this service is currently listening on localhost
    • Constructor Summary

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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void handleClient​(java.net.ServerSocket server)
      waits for the next client to connect.
      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 one after another
      • Methods inherited from class java.lang.Object

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

      • FILE

        private static final java.lang.String FILE
        path to file which will be sent to clients; relative to current working directory (e.g. project root)
        See Also:
        Constant Field Values
      • port

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

        private final int backlog
        requested maximum length of the queue of incoming connections.
    • Constructor Detail

      • FileServerIterativ

        public FileServerIterativ​(int port,
                                  int backlog)
        the only constructor for this class
        Parameters:
        port - port on which this service will be listening on localhost
        backlog - requested maximum length of the queue of incoming connections.
    • Method Detail

      • start

        public void start()
        creates server socket on localhost:port, infinitely handles connections to clients one after another
      • handleClient

        private void handleClient​(java.net.ServerSocket server)
        waits for the next client to connect. Upon connection sends a manually defined file back to client. closes the connection directly afterwards and handles then next client
        Parameters:
        server - "welcome socket" on which server is listening for clients
      • 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