Skip to content

Commit f32532d

Browse files
authored
swallowed flood which dragon cast out of his mouth
And the earth helped the woman, and the earth opened her mouth, and swallowed up the flood which the dragon cast out of his mouth. (Revelation 12:16)
1 parent 8fe5a41 commit f32532d

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
//And the earth helped the woman, and the earth opened her mouth, and swallowed up the flood which the dragon cast out of his mouth. (Revelation 12:16)
3+
4+
package com.javarush.task.task40.task4005;
5+
6+
import java.net.ServerSocket;
7+
import java.net.Socket;
8+
9+
/*
10+
Сокетный сервер и клиент
11+
*/
12+
13+
public class Server {
14+
15+
public static void main(String[] args) {
16+
int port = 4444;
17+
18+
try (ServerSocket serverSocket = new ServerSocket(port)) {
19+
while (true) {
20+
Socket socket = serverSocket.accept();
21+
new Handler(socket).start();
22+
}
23+
} catch (Exception e) {
24+
e.printStackTrace();
25+
}
26+
}
27+
28+
private static class Handler extends Thread {
29+
private Socket socket;
30+
31+
public Handler(Socket socket) {
32+
this.socket = socket;
33+
}
34+
35+
@Override
36+
public void run() {
37+
try (Connection connection = new Connection(socket)) {
38+
while (true) {
39+
String message = connection.receive();
40+
41+
if (message.equals("exit"))
42+
break;
43+
44+
System.out.println(message);
45+
46+
connection.send("Echo: " + message);
47+
}
48+
} catch (Exception e) {
49+
}
50+
}
51+
52+
}
53+
}
54+
55+
/*
56+
Сокетный сервер и клиент
57+
58+
Есть сервер, он принимает входящие сообщения от клиентов и отвечает им echo.
59+
60+
Есть клиенты, они считывают сообщения с клавиатуры и отправляют их серверу.
61+
62+
Программа запускается, но не работает.
63+
64+
Разберись в чем проблема, внеси минимальные изменения в код, чтобы все заработало.
65+
66+
67+
68+
69+
70+
Требования:
71+
72+
1. Класс Client не изменяй.
73+
74+
2. Класс Server не изменяй.
75+
76+
3. Внеси необходимые изменения в класс Connection.
77+
78+
4. Поля в классе Connection не изменяй.
79+
*/

0 commit comments

Comments
 (0)