diff --git a/src/main/java/ru/molokoin/ExchangeServer.java b/src/main/java/ru/molokoin/ExchangeServer.java index 60db3a8..7c48459 100644 --- a/src/main/java/ru/molokoin/ExchangeServer.java +++ b/src/main/java/ru/molokoin/ExchangeServer.java @@ -10,8 +10,10 @@ import java.net.ServerSocket; import java.net.Socket; import java.nio.charset.StandardCharsets; -public class ExchangeServer { +public class ExchangeServer{ private static int port = 8081; + private static String link = "localhost"; + private static int num = 0; public static void main(String[] args) { try (ServerSocket serverSocket = new ServerSocket(port)) { @@ -21,6 +23,7 @@ public class ExchangeServer { // ожидаем подключения Socket socket = serverSocket.accept(); System.out.println("Client connected ..."); + num++; // для подключившегося клиента открываем потоки // чтения и записи @@ -32,8 +35,19 @@ public class ExchangeServer { // считываем и печатаем все что было отправлено клиентом System.out.println(); + String firstLine = null; + String querry = null; while (input.ready()) { - System.out.println(input.readLine()); + String line = input.readLine(); + if (firstLine == null){ + firstLine = line; + if(firstLine.startsWith("GET")){ + querry = "GET"; + } + System.out.println("firstLine: " + firstLine); + System.out.println("querry: " + querry); + } + System.out.println(line); } // отправляем ответ @@ -42,14 +56,17 @@ public class ExchangeServer { String fileName = "upload.html"; path = path + "/src/main/webapp/"; File file = new File(path + fileName); + //String text = ""; try (BufferedReader br = new BufferedReader(new FileReader(file))){ String line; while ((line = br.readLine()) != null) { System.out.println(line); output.println(line); + //text = text + " " + line; } output.flush(); } + catch (IOException e) { e.printStackTrace(); } @@ -57,6 +74,7 @@ public class ExchangeServer { // по окончанию выполнения блока try-with-resources потоки, // а вместе с ними и соединение будут закрыты System.out.println("Client disconnected!"); + System.out.println("num: " + num); } } } catch (IOException ex) { diff --git a/src/main/java/ru/molokoin/UploadServer.java b/src/main/java/ru/molokoin/UploadServer.java index 8e74946..368d7e7 100644 --- a/src/main/java/ru/molokoin/UploadServer.java +++ b/src/main/java/ru/molokoin/UploadServer.java @@ -13,6 +13,7 @@ package ru.molokoin; not be liable for any consequences, loss of profit or any other kind of loss, that may occur while using the product itself and/or together with any other software. + */ import java.net.*; diff --git a/src/main/webapp/upload.html b/src/main/webapp/upload.html index 03f31c1..fdfad69 100644 --- a/src/main/webapp/upload.html +++ b/src/main/webapp/upload.html @@ -1,5 +1,7 @@ HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 + +