-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.java
31 lines (27 loc) · 978 Bytes
/
Server.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
public static Socket clientSocket;
public static ServerSocket server;
public static BufferedReader in;
public static BufferedWriter out;
public static void main(String[] args) throws IOException {
try {
server = new ServerSocket(3345);
System.out.println("Server Start!");
clientSocket = server.accept();
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
// и отправлять
out = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
String word = in.readLine();
System.out.println(word);
out.write("It server, you wrote " + word + "\n");
out.flush();
} finally {
clientSocket.close();
in.close();
out.close();
}
}
}