Skip to content

Commit 97f9001

Browse files
authored
earth opened her mouth, and swallowed up the flood
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 f32532d commit 97f9001

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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.io.BufferedReader;
7+
import java.io.InputStreamReader;
8+
import java.net.Socket;
9+
10+
/*
11+
Сокетный сервер и клиент
12+
*/
13+
14+
public class Client {
15+
private Connection connection;
16+
17+
private String getServerAddress() {
18+
return "localhost";
19+
}
20+
21+
private int getServerPort() {
22+
return 4444;
23+
}
24+
25+
public void run() {
26+
BufferedReader bis = new BufferedReader(new InputStreamReader(System.in));
27+
28+
try {
29+
connection = new Connection(new Socket(getServerAddress(), getServerPort()));
30+
31+
SocketThread socketThread = new SocketThread();
32+
socketThread.setDaemon(true);
33+
socketThread.start();
34+
35+
while (true) {
36+
String text = bis.readLine();
37+
if (text.equalsIgnoreCase("exit"))
38+
break;
39+
connection.send(text);
40+
}
41+
} catch (Exception e) {
42+
e.printStackTrace();
43+
}
44+
}
45+
46+
public static void main(String[] args) {
47+
Client client = new Client();
48+
client.run();
49+
}
50+
51+
public class SocketThread extends Thread {
52+
@Override
53+
public void run() {
54+
try {
55+
while (true) {
56+
String message = connection.receive();
57+
System.out.println(message);
58+
}
59+
60+
} catch (Exception e) {
61+
e.printStackTrace();
62+
}
63+
}
64+
}
65+
}
66+
67+
/*
68+
Сокетный сервер и клиент
69+
70+
Есть сервер, он принимает входящие сообщения от клиентов и отвечает им echo.
71+
72+
Есть клиенты, они считывают сообщения с клавиатуры и отправляют их серверу.
73+
74+
Программа запускается, но не работает.
75+
76+
Разберись в чем проблема, внеси минимальные изменения в код, чтобы все заработало.
77+
78+
79+
80+
81+
82+
Требования:
83+
84+
1. Класс Client не изменяй.
85+
86+
2. Класс Server не изменяй.
87+
88+
3. Внеси необходимые изменения в класс Connection.
89+
90+
4. Поля в классе Connection не изменяй.
91+
*/

0 commit comments

Comments
 (0)