-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocketClient.java
More file actions
37 lines (30 loc) · 922 Bytes
/
SocketClient.java
File metadata and controls
37 lines (30 loc) · 922 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
27
28
29
30
31
32
33
34
35
36
37
package com.zs.system.io;
import java.io.*;
import java.net.Socket;
/**
* @author: 马士兵教育
* @create: 2020-05-17 16:18
*/
public class SocketClient {
public static void main(String[] args) {
try {
Socket client = new Socket("127.0.0.1",9090);
client.setSendBufferSize(20);
client.setTcpNoDelay(true);
OutputStream out = client.getOutputStream();
InputStream in = System.in;
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
while(true){
String line = reader.readLine();
if(line != null ){
byte[] bb = line.getBytes();
for (byte b : bb) {
out.write(b);
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}