esoe 2 years ago
parent
commit
d2af8ca65f
  1. 22
      src/main/java/ru/molokoin/ExchangeServer.java
  2. 1
      src/main/java/ru/molokoin/UploadServer.java
  3. 2
      src/main/webapp/upload.html
  4. BIN
      target/classes/ru/molokoin/ExchangeServer.class
  5. BIN
      target/classes/ru/molokoin/UploadServer.class

22
src/main/java/ru/molokoin/ExchangeServer.java

@ -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) {

1
src/main/java/ru/molokoin/UploadServer.java

@ -13,6 +13,7 @@ package ru.molokoin; @@ -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.*;

2
src/main/webapp/upload.html

@ -1,5 +1,7 @@ @@ -1,5 +1,7 @@
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
<form enctype="multipart/form-data" method="post">
<p><input type="file" name="f">
<input type="submit" value="send"></p>

BIN
target/classes/ru/molokoin/ExchangeServer.class

Binary file not shown.

BIN
target/classes/ru/molokoin/UploadServer.class

Binary file not shown.
Loading…
Cancel
Save