File tree Expand file tree Collapse file tree 3 files changed +10
-7
lines changed
main/java/com/examplehub/basics/network
test/java/com/examplehub/basics/network Expand file tree Collapse file tree 3 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -16,16 +16,18 @@ public static void main(String[] args) throws IOException {
16
16
clientSocket .close ();
17
17
System .out .println ("disconnected." );
18
18
}
19
- private static void handle (InputStream inputStream , OutputStream outputStream ) throws IOException {
19
+
20
+ private static void handle (InputStream inputStream , OutputStream outputStream )
21
+ throws IOException {
20
22
var writer = new BufferedWriter (new OutputStreamWriter (outputStream , StandardCharsets .UTF_8 ));
21
23
var reader = new BufferedReader (new InputStreamReader (inputStream , StandardCharsets .UTF_8 ));
22
24
Scanner scanner = new Scanner (System .in );
23
25
System .out .println ("[server] " + reader .readLine ());
24
- for (;; ) {
26
+ for (; ; ) {
25
27
System .out .print (">>> " ); // 打印提示
26
28
String s = scanner .nextLine (); // 读取一行输入
27
29
writer .write (s + System .lineSeparator ());
28
- // writer.newLine();
30
+ // writer.newLine();
29
31
writer .flush ();
30
32
String resp = reader .readLine ();
31
33
System .out .println ("<<< " + resp );
Original file line number Diff line number Diff line change @@ -12,9 +12,10 @@ static class ServerHandler implements Runnable {
12
12
public ServerHandler (Socket socket ) {
13
13
this .socket = socket ;
14
14
}
15
+
15
16
public void run () {
16
17
try (InputStream inputStream = this .socket .getInputStream ()) {
17
- try (OutputStream outputStream = this .socket .getOutputStream ()) {
18
+ try (OutputStream outputStream = this .socket .getOutputStream ()) {
18
19
handle (inputStream , outputStream );
19
20
}
20
21
} catch (Exception e ) {
@@ -52,6 +53,6 @@ public static void main(String[] args) throws IOException {
52
53
System .out .println ("connected from " + socket .getRemoteSocketAddress ());
53
54
new Thread (new ServerHandler (socket )).start ();
54
55
}
55
- //TODO
56
+ // TODO
56
57
}
57
58
}
Original file line number Diff line number Diff line change 1
1
package com .examplehub .basics .network ;
2
2
3
3
class SocketServerTest {
4
- //TODO
5
- }
4
+ // TODO
5
+ }
You can’t perform that action at this time.
0 commit comments