Repository navigation
Expand file tree
/
Copy pathClient.java
More file actions
48 lines (44 loc) · 1.57 KB
/
Copy pathClient.java
File metadata and controls
48 lines (44 loc) · 1.57 KB
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
38
39
40
41
42
43
44
45
46
47
48
package MultiThreadServer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
public class Client {
public Runnable getRunnable() {
return new Runnable() {
@Override
public void run() {
int port = 8011;
try {
InetAddress address = InetAddress.getByName("localhost");
Socket socket = new Socket(address, port);
try {
PrintWriter toSocket = new PrintWriter(socket.getOutputStream());
BufferedReader fromClient = new BufferedReader(new InputStreamReader(socket.getInputStream()));
toSocket.println("Hello from the SingleServer.Client");
String line = fromClient.readLine();
System.out.println("Response from the socket is:" + line);
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
};
}
public static void main(String[] args) {
Client client=new Client();
for(int i=0;i<100;i++){
try{
Thread thread=new Thread(client.getRunnable());
thread.start();
}catch (Exception e){
return;
}
}
}
}