commit e257ae8f2ec3d005c9a1497ac41fc550cf368a5b
Author: Eliška Mourycová <eliska.mourycova@seznam.cz>
Date:   Fri Apr 30 22:57:28 2021 +0200

    Re #8770. Somewhat working example of HttpListener. Can receive requests from other than host machine. Firawall adjustment was necessary.

diff --git a/Server/ServerApp/Connection/SocketListener.cs b/Server/ServerApp/Connection/SocketListener.cs
index d16110c..1bfa176 100644
--- a/Server/ServerApp/Connection/SocketListener.cs
+++ b/Server/ServerApp/Connection/SocketListener.cs
@@ -3,287 +3,379 @@
 //
 
 using System;
+using System.IO;
 using System.Net;
 using System.Net.Sockets;
 using System.Text;
 using System.Threading;
+using System.Web;
 
 namespace ServerApp.Connection
 {
-    /// <summary>
-    /// State object for reading client data asynchronously
-    /// </summary>
-    public class StateObject
-    {
-        // Client  socket.
-        public Socket WorkSocket = null;
-        // Size of receive buffer.
-        public const int BUFFER_SIZE = 1024;
-        // Receive buffer.
-        public byte[] Buffer = new byte[BUFFER_SIZE];
-        // Received data string.
-        public StringBuilder StrBuilder = new StringBuilder();
-    }
-
-    /// <summary>
-    /// This class takes care of client connection. It serves clients asynchronously.
-    /// </summary>
-    public class AsynchronousSocketListener
-    {
-        // port numbers:
-        private const int PORT_NO = 11000;
-        private const int ADMIN_PORT_NO = 10000;
-
-
-        // Thread signal
-        private ManualResetEvent allDone = new ManualResetEvent(false);
-
-        /// <summary>
-        /// Starts listening and accepting connections. It serves requests when they come.
-        /// </summary>
-        public void StartListening()
-        {
-            // Data buffer for incoming data.
-            byte[] bytes = new Byte[1024];
-
-            // Establish the local endpoint for the socket:
-            IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
-
-            // Get the IP of the machine - UNUSED ATM, USING LOOPBACK ON LOCALHOST
-            IPAddress ipAddress = ipHostInfo.AddressList[1];
-            Console.WriteLine("machine ip: " + ipAddress.ToString());
-            IPEndPoint localEndPoint = new IPEndPoint(/*ipAddress*/IPAddress.Loopback, PORT_NO);
-            IPEndPoint localEndPointAdmin = new IPEndPoint(/*ipAddress*/IPAddress.Loopback, ADMIN_PORT_NO);
-
-            // Create a TCP/IP socket.
-            Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
-            Socket listenerAdmin = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
-
-            // Bind the socket to the local endpoint and listen for incoming connections.
-            try
-            {
-                listener.Bind(localEndPoint);
-                listener.Listen(100);
-
-                listenerAdmin.Bind(localEndPointAdmin);
-                listenerAdmin.Listen(1);
-
-                // keep accepting
-                while (true)
-                {
-                    // Set the event to nonsignaled state.
-                    allDone.Reset();
-
-                    // Start an asynchronous socket to listen for connections.
-                    Console.WriteLine("Waiting for a connection...");
-                    listener.BeginAccept(new AsyncCallback(AcceptCallback), listener);
-                    listenerAdmin.BeginAccept(new AsyncCallback(AcceptCallback), listenerAdmin);
-
-                    // Wait until a connection is made before continuing.
-                    allDone.WaitOne();
-                }
-
-            }
-            catch (Exception e)
-            {
-                // bind failed
-                Console.WriteLine(e.ToString());
-            }
-
-            Console.WriteLine("\nPress ENTER to continue...");
-            Console.Read();
-
-        }
-
-        // Routine for when BeginAccept on the given listener ended
-        private void AcceptCallback(IAsyncResult ar)
-        {
-            // Signal the main thread to continue.
-            allDone.Set();
-            Console.WriteLine("Accepted a connection.");
+  //  /// <summary>
+  //  /// State object for reading client data asynchronously
+  //  /// </summary>
+  //  public class StateObject
+  //  {
+  //      // Client  socket.
+  //      public Socket WorkSocket = null;
+  //      // Size of receive buffer.
+  //      public const int BUFFER_SIZE = 1024;
+  //      // Receive buffer.
+  //      public byte[] Buffer = new byte[BUFFER_SIZE];
+  //      // Received data string.
+  //      public StringBuilder StrBuilder = new StringBuilder();
+  //  }
+
+  //  /// <summary>
+  //  /// This class takes care of client connection. It serves clients asynchronously.
+  //  /// </summary>
+  //  public class AsynchronousSocketListener
+  //  {
+  //      // port numbers:
+  //      private const int PORT_NO = 11000;
+  //      private const int ADMIN_PORT_NO = 10000;
+
+
+  //      // Thread signal
+  //      private ManualResetEvent allDone = new ManualResetEvent(false);
+
+  //      /// <summary>
+  //      /// Starts listening and accepting connections. It serves requests when they come.
+  //      /// </summary>
+  //      public void StartListening()
+  //      {
+  //          // Data buffer for incoming data.
+  //          byte[] bytes = new Byte[1024];
+
+  //          // Establish the local endpoint for the socket:
+  //          IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
+
+  //          // Get the IP of the machine - UNUSED ATM, USING LOOPBACK ON LOCALHOST
+  //          IPAddress ipAddress = ipHostInfo.AddressList[1];
+  //          Console.WriteLine("machine ip: " + ipAddress.ToString());
+  //          IPEndPoint localEndPoint = new IPEndPoint(/*ipAddress*/IPAddress.Loopback, PORT_NO);
+  //          IPEndPoint localEndPointAdmin = new IPEndPoint(/*ipAddress*/IPAddress.Loopback, ADMIN_PORT_NO);
+
+  //          // Create a TCP/IP socket.
+  //          Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+  //          Socket listenerAdmin = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+
+  //          // Bind the socket to the local endpoint and listen for incoming connections.
+  //          try
+  //          {
+  //              listener.Bind(localEndPoint);
+  //              listener.Listen(100);
+
+  //              listenerAdmin.Bind(localEndPointAdmin);
+  //              listenerAdmin.Listen(1);
+
+  //              // keep accepting
+  //              while (true)
+  //              {
+  //                  // Set the event to nonsignaled state.
+  //                  allDone.Reset();
+
+  //                  // Start an asynchronous socket to listen for connections.
+  //                  Console.WriteLine("Waiting for a connection...");
+  //                  listener.BeginAccept(new AsyncCallback(AcceptCallback), listener);
+  //                  listenerAdmin.BeginAccept(new AsyncCallback(AcceptCallback), listenerAdmin);
+
+  //                  // Wait until a connection is made before continuing.
+  //                  allDone.WaitOne();
+  //              }
+
+  //          }
+  //          catch (Exception e)
+  //          {
+  //              // bind failed
+  //              Console.WriteLine(e.ToString());
+  //          }
+
+  //          Console.WriteLine("\nPress ENTER to continue...");
+  //          Console.Read();
+
+  //      }
+
+  //      // Routine for when BeginAccept on the given listener ended
+  //      private void AcceptCallback(IAsyncResult ar)
+  //      {
+  //          // Signal the main thread to continue.
+  //          allDone.Set();
+  //          Console.WriteLine("Accepted a connection.");
             
 
-            // Get the socket that handles the client request.
-            Socket listener = (Socket)ar.AsyncState;
-            Socket handler = listener.EndAccept(ar);
+  //          // Get the socket that handles the client request.
+  //          Socket listener = (Socket)ar.AsyncState;
+  //          Socket handler = listener.EndAccept(ar);
 
-            // debug
-            Console.WriteLine("handler: ");
-            Console.WriteLine("I am connected to " + IPAddress.Parse(((IPEndPoint)handler.RemoteEndPoint).Address.ToString()) + " on port number " + ((IPEndPoint)handler.RemoteEndPoint).Port.ToString());
-            Console.WriteLine("My local IpAddress is : " + IPAddress.Parse(((IPEndPoint)handler.LocalEndPoint).Address.ToString()) + ". I am connected on port number " + ((IPEndPoint)handler.LocalEndPoint).Port.ToString());
+  //          // debug
+  //          Console.WriteLine("handler: ");
+  //          Console.WriteLine("I am connected to " + IPAddress.Parse(((IPEndPoint)handler.RemoteEndPoint).Address.ToString()) + " on port number " + ((IPEndPoint)handler.RemoteEndPoint).Port.ToString());
+  //          Console.WriteLine("My local IpAddress is : " + IPAddress.Parse(((IPEndPoint)handler.LocalEndPoint).Address.ToString()) + ". I am connected on port number " + ((IPEndPoint)handler.LocalEndPoint).Port.ToString());
 
 
 
 
-            // Create the state object.
-            StateObject state = new StateObject();
-            state.WorkSocket = handler;
-            handler.BeginReceive(state.Buffer, 0, StateObject.BUFFER_SIZE, 0, new AsyncCallback(ReadCallback), state);
+  //          // Create the state object.
+  //          StateObject state = new StateObject();
+  //          state.WorkSocket = handler;
+  //          handler.BeginReceive(state.Buffer, 0, StateObject.BUFFER_SIZE, 0, new AsyncCallback(ReadCallback), state);
             
-        }
+  //      }
+
+  //      // Routine for when BeginReceive on the given listener ended
+  //      private void ReadCallback(IAsyncResult ar)
+  //      {
+  //          // string for the received message
+  //          String content = String.Empty;
+
+  //          // Retrieve the state object and the handler socket
+  //          // from the asynchronous state object.
+  //          StateObject state = (StateObject)ar.AsyncState;
+  //          Socket handler = state.WorkSocket;
+
+  //          // check if we're still connected
+  //          if (!SocketConnected(handler))
+		//	{
+  //              // if the client isn't connected anymore, take care of cleanup
+  //              Console.WriteLine("Closing connection - unexpected...");
+  //              CloseConnection(handler);
+
+  //              // return so that we don't attempt to read from a non-existent stream
+  //              return;
+  //          }
+
+  //          // check if it is admin's request we're serving
+  //          bool admin = ((IPEndPoint)handler.LocalEndPoint).Port == ADMIN_PORT_NO;
+
+  //          // Read data from the client socket. 
+  //          int bytesRead = handler.EndReceive(ar);
+
+  //          if (bytesRead > 0)
+  //          {
+  //              // There  might be more data, so store the data received so far.
+  //              state.StrBuilder.Append(Encoding.ASCII.GetString(state.Buffer, 0, bytesRead));
+
+  //              // Check for end-of-file tag. If it is not there, read more data.
+  //              content = state.StrBuilder.ToString();
+  //              if (content.IndexOf("!") > -1)
+  //              {
+  //                  // All the data has been read from the client. Display it on the console.
+  //                  Console.WriteLine("Read {0} bytes from socket. \n Data : {1}", content.Length, content);
+
+  //                  // parse the message and determine the response:
+  //                  content = ParseMessageAndBuildAnswer(content, admin);
+
+  //                  // check if the client wishes to close the connection:
+  //                  if (content.Equals("bye!"))
+  //                  {
+  //                      Console.WriteLine("Closing connection - expected...");
+  //                      //handler.Shutdown(SocketShutdown.Both);
+  //                      //handler.Close();
+  //                      CloseConnection(handler);
+  //                      return;
+  //                  }
+
+  //                  // Send a response to the client
+  //                  Send(handler, content);
+					
+  //                  // clear the string
+  //                  state.StrBuilder.Clear();
+
+  //                  // begin receiving another message:
+  //                  handler.BeginReceive(state.Buffer, 0, StateObject.BUFFER_SIZE, 0, new AsyncCallback(ReadCallback), state);
+  //              }
+  //              else
+  //              {
+  //                  // Not all data received. Get more.
+  //                  handler.BeginReceive(state.Buffer, 0, StateObject.BUFFER_SIZE, 0, new AsyncCallback(ReadCallback), state);
+  //              }
+  //          }
+  //      }
+
+  //      // Takes care of sending data to a connected client
+  //      private void Send(Socket handler, String data)
+  //      {
+  //          // Convert the string data to byte data using ASCII encoding.
+  //          byte[] byteData = Encoding.ASCII.GetBytes(data);
+
+  //          // Begin sending the data to the remote device.
+  //          handler.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), handler);
+  //      }
+
+  //      // Routine for when BeginSend on the given listener ended
+  //      private void SendCallback(IAsyncResult ar)
+  //      {
+  //          try
+  //          {
+  //              // Retrieve the socket from the state object.
+  //              Socket handler = (Socket)ar.AsyncState;
+
+  //              // Complete sending the data to the remote device.
+  //              int bytesSent = handler.EndSend(ar);
+  //              Console.WriteLine("Sent {0} bytes to client.", bytesSent);
+
+
+  //              //handler.Shutdown(SocketShutdown.Both);
+  //              //handler.Close();
+
+  //          }
+  //          catch (Exception e)
+  //          {
+  //              // close connection here?
+
+  //              Console.WriteLine(e.ToString());
+  //          }
+  //      }
+
+
+  //      /// <summary>
+  //      /// Parses the incoming request and determines the response.
+  //      /// </summary>
+  //      /// <param name="message">The incoming message from the client</param>
+  //      /// <param name="admin">A flag saying whether it is admin's request</param>
+  //      /// <returns></returns>
+  //      private string ParseMessageAndBuildAnswer(string message, bool admin)
+		//{
+  //          Console.WriteLine("Parsing message from admin: " + admin);
+  //          string ans = "";
+
+		//	if (message.Equals("hello!"))
+		//	{
+  //              ans = "hello to you too.";
+		//	}
+  //          else if (message.Equals("weather!"))
+		//	{
+  //              ans = "weather will be nice";
+  //          }
+  //          else if (message.Equals("bye!"))
+		//	{
+  //              ans = "bye!";
+		//	}
+  //          else
+		//	{
+  //              // here bye too, if we want to disconnect clients who don't follow protocol
+  //              ans = "bye!";//"i didnt understand that";
+
+  //          }
+
+  //          return ans;
+		//}
+
+  //      /// <summary>
+  //      /// Closes the connection on the passed Socket
+  //      /// </summary>
+  //      /// <param name="s">The socket to close the connection for</param>
+  //      private void CloseConnection(Socket s)
+		//{
+  //          s.Shutdown(SocketShutdown.Both);
+  //          s.Close();
+  //      }
+
+  //      /// <summary>
+  //      /// Checks whether the connection on a given socket is active
+  //      /// </summary>
+  //      /// <param name="s">The socket to check for connection activity</param>
+  //      /// <returns>True if the connection is active, false otherwise</returns>
+  //      private bool SocketConnected(Socket s)
+  //      {
+  //          bool part1 = s.Poll(1000, SelectMode.SelectRead);
+  //          bool part2 = (s.Available == 0);
+  //          if (part1 && part2)
+  //              return false;
+  //          else
+  //              return true;
+  //      }
+  //  }
+
+
+	public class ConnectionListener
+	{
+		private readonly int PORT;
+
+		public ConnectionListener(int port)
+		{
+			this.PORT = port;
+		}
 
-        // Routine for when BeginReceive on the given listener ended
-        private void ReadCallback(IAsyncResult ar)
-        {
-            // string for the received message
-            String content = String.Empty;
-
-            // Retrieve the state object and the handler socket
-            // from the asynchronous state object.
-            StateObject state = (StateObject)ar.AsyncState;
-            Socket handler = state.WorkSocket;
-
-            // check if we're still connected
-            if (!SocketConnected(handler))
-			{
-                // if the client isn't connected anymore, take care of cleanup
-                Console.WriteLine("Closing connection - unexpected...");
-                CloseConnection(handler);
-
-                // return so that we don't attempt to read from a non-existent stream
-                return;
-            }
+		public void StartListening()
+		{
+            string ip = GetLocalIPAddress();
+            Console.WriteLine("ip : " + ip);
+            HttpListener server = new HttpListener();
+            server.Prefixes.Add("http://*:8000/work/");
+            server.Prefixes.Add("http://localhost:8000/work/");
+            server.Prefixes.Add("http://127.0.0.1:8000/work/");
+            server.Prefixes.Add($"http://{ip}:8000/work/");
+            server.Prefixes.Add("http://+:8000/work/");
 
-            // check if it is admin's request we're serving
-            bool admin = ((IPEndPoint)handler.LocalEndPoint).Port == ADMIN_PORT_NO;
+            server.Start();
 
-            // Read data from the client socket. 
-            int bytesRead = handler.EndReceive(ar);
+            Console.WriteLine("Listening...");
 
-            if (bytesRead > 0)
+            while (true)
             {
-                // There  might be more data, so store the data received so far.
-                state.StrBuilder.Append(Encoding.ASCII.GetString(state.Buffer, 0, bytesRead));
+                Console.WriteLine("waiting for request?");
+                //Console.ReadLine();
 
-                // Check for end-of-file tag. If it is not there, read more data.
-                content = state.StrBuilder.ToString();
-                if (content.IndexOf("!") > -1)
-                {
-                    // All the data has been read from the client. Display it on the console.
-                    Console.WriteLine("Read {0} bytes from socket. \n Data : {1}", content.Length, content);
-
-                    // parse the message and determine the response:
-                    content = ParseMessageAndBuildAnswer(content, admin);
-
-                    // check if the client wishes to close the connection:
-                    if (content.Equals("bye!"))
-                    {
-                        Console.WriteLine("Closing connection - expected...");
-                        //handler.Shutdown(SocketShutdown.Both);
-                        //handler.Close();
-                        CloseConnection(handler);
-                        return;
-                    }
-
-                    // Send a response to the client
-                    Send(handler, content);
-					
-                    // clear the string
-                    state.StrBuilder.Clear();
+                HttpListenerContext context = server.GetContext();
 
-                    // begin receiving another message:
-                    handler.BeginReceive(state.Buffer, 0, StateObject.BUFFER_SIZE, 0, new AsyncCallback(ReadCallback), state);
+
+                if (context.Request.HttpMethod == "GET") // when client says download
+                {
+                    HttpListenerResponse response = context.Response;
+                    response.AddHeader("Access-Control-Allow-Credentials", "true");
+                    response.AddHeader("Access-Control-Expose-Headers", "ETag");
+                    response.AddHeader("Access-Control-Allow-Headers", "Accept, X-Access-Token, X-Application-Name, X-Request-Sent-Time");
+                    response.AddHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
+                    response.AddHeader("Access-Control-Allow-Origin", "*");
+
+                    //string page = Directory.GetCurrentDirectory() + context.Request.Url.LocalPath;
+                    // if (page == string.Empty)
+                    //     page = "test.txt";
+                    // 
+                    // TextReader tr = new StreamReader(page);
+                    // string msg = tr.ReadToEnd();
+
+                    int rand = new Random().Next(1, 10);
+                    string msg = "This is a response from the server :) " + rand;
+
+                    byte[] buffer = Encoding.UTF8.GetBytes(msg);
+
+                    response.ContentLength64 = buffer.Length;
+                    Stream st = response.OutputStream;
+                    st.Write(buffer, 0, buffer.Length);
+
+                    
+                    context.Response.Close();
                 }
-                else
+
+                else if (context.Request.HttpMethod == "POST") // when client says upload
                 {
-                    // Not all data received. Get more.
-                    handler.BeginReceive(state.Buffer, 0, StateObject.BUFFER_SIZE, 0, new AsyncCallback(ReadCallback), state);
+                    string text;
+                    using (var reader = new StreamReader(context.Request.InputStream, context.Request.ContentEncoding))
+                        text = reader.ReadToEnd();
+                    Console.WriteLine("Received request:");
+                    Console.WriteLine(HttpUtility.UrlDecode(text));
+
+                    context.Response.Close();
                 }
             }
         }
 
-        // Takes care of sending data to a connected client
-        private void Send(Socket handler, String data)
-        {
-            // Convert the string data to byte data using ASCII encoding.
-            byte[] byteData = Encoding.ASCII.GetBytes(data);
-
-            // Begin sending the data to the remote device.
-            handler.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), handler);
-        }
 
-        // Routine for when BeginSend on the given listener ended
-        private void SendCallback(IAsyncResult ar)
+        private string GetLocalIPAddress()
         {
-            try
-            {
-                // Retrieve the socket from the state object.
-                Socket handler = (Socket)ar.AsyncState;
-
-                // Complete sending the data to the remote device.
-                int bytesSent = handler.EndSend(ar);
-                Console.WriteLine("Sent {0} bytes to client.", bytesSent);
-
-
-                //handler.Shutdown(SocketShutdown.Both);
-                //handler.Close();
-
-            }
-            catch (Exception e)
+            var host = Dns.GetHostEntry(Dns.GetHostName());
+            foreach (var ip in host.AddressList)
             {
-                // close connection here?
-
-                Console.WriteLine(e.ToString());
-            }
-        }
-
-
-        /// <summary>
-        /// Parses the incoming request and determines the response.
-        /// </summary>
-        /// <param name="message">The incoming message from the client</param>
-        /// <param name="admin">A flag saying whether it is admin's request</param>
-        /// <returns></returns>
-        private string ParseMessageAndBuildAnswer(string message, bool admin)
-		{
-            Console.WriteLine("Parsing message from admin: " + admin);
-            string ans = "";
-
-			if (message.Equals("hello!"))
-			{
-                ans = "hello to you too.";
-			}
-            else if (message.Equals("weather!"))
-			{
-                ans = "weather will be nice";
-            }
-            else if (message.Equals("bye!"))
-			{
-                ans = "bye!";
-			}
-            else
-			{
-                // here bye too, if we want to disconnect clients who don't follow protocol
-                ans = "bye!";//"i didnt understand that";
-
+                if (ip.AddressFamily == AddressFamily.InterNetwork)
+                {
+                    return ip.ToString();
+                }
             }
-
-            return ans;
-		}
-
-        /// <summary>
-        /// Closes the connection on the passed Socket
-        /// </summary>
-        /// <param name="s">The socket to close the connection for</param>
-        private void CloseConnection(Socket s)
-		{
-            s.Shutdown(SocketShutdown.Both);
-            s.Close();
-        }
-
-        /// <summary>
-        /// Checks whether the connection on a given socket is active
-        /// </summary>
-        /// <param name="s">The socket to check for connection activity</param>
-        /// <returns>True if the connection is active, false otherwise</returns>
-        private bool SocketConnected(Socket s)
-        {
-            bool part1 = s.Poll(1000, SelectMode.SelectRead);
-            bool part2 = (s.Available == 0);
-            if (part1 && part2)
-                return false;
-            else
-                return true;
+            throw new Exception("No network adapters with an IPv4 address in the system!");
         }
     }
    
diff --git a/Server/ServerApp/Program.cs b/Server/ServerApp/Program.cs
index c34d559..8303183 100644
--- a/Server/ServerApp/Program.cs
+++ b/Server/ServerApp/Program.cs
@@ -30,12 +30,12 @@ namespace ServerApp
         static void Main(string[] args)
         {
 
-            Config config = FillConfigInfo(args);
-			if (config == null)
-			{
-				Console.ReadLine();
-				return;
-			}
+   //         Config config = FillConfigInfo(args);
+			//if (config == null)
+			//{
+			//	Console.ReadLine();
+			//	return;
+			//}
 
 			// create a thread for commands accepting:
 			//Thread inputThread = new Thread(CommandsAcceptor.AcceptCommand);
@@ -49,57 +49,41 @@ namespace ServerApp
 
 
 			// test scenario - data download:
-			DataDownloader dd = new DataDownloader(config.DataRootDir, config.DataWebsite, config.DownloadedFilesNaming);
-			dd.OverwriteExisting = false;
-			List<string> savedFiles = new List<string>();
-			//savedFiles.AddRange(dd.DownloadData(DataType.JIS, DataFormat.CSV, new Date(1, 2019), new Date(12, 2020)));
-			//savedFiles.AddRange(dd.DownloadData(DataType.STROJE, DataFormat.CSV, new Date(1, 2017), new Date(12, 2020)));
-			//savedFiles.AddRange(dd.DownloadData(DataType.POCASI, DataFormat.CSV, new Date(1, 2017), new Date(12, 2020)));
-
-
-
-			Console.WriteLine("Saved files: ");
-			foreach (string s in savedFiles)
-			{
-				Console.WriteLine(s);
-			}
-
-			Console.WriteLine("subdirectories: ");
-			foreach (KeyValuePair<DataType, string> kvp in dd.DataSubDirectories)
-			{
-				Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
-			}
-
-			List<string> retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], new Date(10, 2019), new Date(12, 2020));
-			Console.WriteLine("Retrieved data: ");
-			foreach (string s in retrievedData)
-			{
-				Console.WriteLine(s);
-			}
-
+			//DataDownloader dd = new DataDownloader(config.DataRootDir, config.DataWebsite, config.DownloadedFilesNaming);
+			//dd.OverwriteExisting = false;
+			//List<string> savedFiles = new List<string>();
+			////savedFiles.AddRange(dd.DownloadData(DataType.JIS, DataFormat.CSV, new Date(1, 2019), new Date(12, 2020)));
+			////savedFiles.AddRange(dd.DownloadData(DataType.STROJE, DataFormat.CSV, new Date(1, 2017), new Date(12, 2020)));
+			////savedFiles.AddRange(dd.DownloadData(DataType.POCASI, DataFormat.CSV, new Date(1, 2017), new Date(12, 2020)));
 
 
 
+			//Console.WriteLine("Saved files: ");
+			//foreach (string s in savedFiles)
+			//{
+			//	Console.WriteLine(s);
+			//}
 
+			//Console.WriteLine("subdirectories: ");
+			//foreach (KeyValuePair<DataType, string> kvp in dd.DataSubDirectories)
+			//{
+			//	Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
+			//}
 
-			// date testing
-			//Date d1 = new Date(2, 2020);
-			//Date d2 = new Date(1, 2019);
+			//List<string> retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], new Date(10, 2019), new Date(12, 2020));
+			//Console.WriteLine("Retrieved data: ");
+			//foreach (string s in retrievedData)
+			//{
+			//	Console.WriteLine(s);
+			//}
 
-			//Console.WriteLine("equals" + d1.Equals(d2));
-			//Console.WriteLine("==" + (d1 == d2));
-			//Console.WriteLine("!=" + (d1 != d2));
-			//Console.WriteLine(">" + (d1 > d2));
-			//Console.WriteLine("<" + (d1 < d2));
-			//Console.WriteLine(">=" + (d1 >= d2));
-			//Console.WriteLine("<=" + (d1 <= d2));
 
 
 
 
 			// test - connection:
-			//AsynchronousSocketListener asl = new AsynchronousSocketListener();
-			//asl.StartListening();
+			ConnectionListener cl = new ConnectionListener(8000/*int.Parse(config.Port)*/);
+			cl.StartListening();
 
 
 			//NaiveBayesClassifier naiveBayesClassifier = new NaiveBayesClassifier();
diff --git a/Server/ServerApp/ServerApp.csproj b/Server/ServerApp/ServerApp.csproj
index 3d8a32b..a6621ee 100644
--- a/Server/ServerApp/ServerApp.csproj
+++ b/Server/ServerApp/ServerApp.csproj
@@ -121,6 +121,7 @@
     <Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
       <HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
     </Reference>
+    <Reference Include="System.Web" />
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Data.DataSetExtensions" />
     <Reference Include="Microsoft.CSharp" />
