-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
47 lines (44 loc) · 1.56 KB
/
Client.java
File metadata and controls
47 lines (44 loc) · 1.56 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
public class Client {
public Runnable getRunnable(){
return new Runnable() {
@Override
public void run(){
int port = 8010;
try{
InetAddress address = InetAddress.getByName("localhost");
Socket socket = new Socket(address,port);
try(
PrintWriter toSocket = new PrintWriter(socket.getOutputStream(), true);
BufferedReader fromSocket = new BufferedReader(new InputStreamReader(socket.getInputStream()));
){
toSocket.println("Hello From Client "+socket.getLocalSocketAddress());
String Line = fromSocket.readLine();
System.out.println("Responce from Server" + 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 ex){
return;
}
}
}
}