-
Notifications
You must be signed in to change notification settings - Fork 1
/
SocketClient.java
35 lines (30 loc) · 957 Bytes
/
SocketClient.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
32
33
34
35
package client;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket.*;
public class SocketClient {
public static void main(String[] args){
try{
while(true){
Socket socket = new Socket("127.0.0.1",2013);
socket.setSoTimeout(60000);
PrintWriter pw = new PrintWriter(socket.getOutputStream(),true);
BufferedReader sysBuff = new BufferedReader(new InputStreamReader(System.in));
pw.println(sysBuff.readLine());
pw.flush();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String res = bufferedReader.readLine();
System.out.println("Server say : "+res);
pw.close();
bufferedReader.close();
socket.close();
}
}catch(Exception e){
System.out.println("Exception : " + e);
}
}
}