forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerSocketLesson.java
More file actions
26 lines (24 loc) · 878 Bytes
/
ServerSocketLesson.java
File metadata and controls
26 lines (24 loc) · 878 Bytes
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
package network;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
public class ServerSocketLesson {
public static void main(String[] args) throws IOException {
try(ServerSocket serverSocket = new ServerSocket(8189);
Socket socket = serverSocket.accept();
Scanner scanner = new Scanner(socket.getInputStream())) {
PrintWriter printWriter = new PrintWriter(socket.getOutputStream(),true);
//printWriter.println("bla");
while (scanner.hasNextLine()) {
String str = scanner.nextLine();
System.out.println(str);
printWriter.println("you've send: " + str);
if(str.equals("exit")) {
break;
}
}
}
}
}