|
|
|
@ -10,8 +10,10 @@ import java.net.ServerSocket;
@@ -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 {
@@ -21,6 +23,7 @@ public class ExchangeServer {
|
|
|
|
|
// ожидаем подключения
|
|
|
|
|
Socket socket = serverSocket.accept(); |
|
|
|
|
System.out.println("Client connected ..."); |
|
|
|
|
num++; |
|
|
|
|
|
|
|
|
|
// для подключившегося клиента открываем потоки
|
|
|
|
|
// чтения и записи
|
|
|
|
@ -32,8 +35,19 @@ public class ExchangeServer {
@@ -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 {
@@ -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 {
@@ -57,6 +74,7 @@ public class ExchangeServer {
|
|
|
|
|
// по окончанию выполнения блока try-with-resources потоки,
|
|
|
|
|
// а вместе с ними и соединение будут закрыты
|
|
|
|
|
System.out.println("Client disconnected!"); |
|
|
|
|
System.out.println("num: " + num); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (IOException ex) { |
|
|
|
|