-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.java
31 lines (24 loc) · 866 Bytes
/
Client.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
import java.util.*;
import java.io.*;
import java.net.*;
public class Client {
public void run () throws UnknownHostException, IOException {
int port =8010;
InetAddress address = InetAddress.getByName("localhost");
Socket socket = new Socket(address, port);
PrintWriter toSocket =new PrintWriter(socket.getOutputStream(),true);
BufferedReader fromSocket =new BufferedReader(new InputStreamReader(socket.getInputStream()));
toSocket.println("hello from the client");
String line = fromSocket.readLine();
System.out.println("response from the server is :"+line);
toSocket.close();
fromSocket.close();
socket.close();
}
public static void main(String[] args) {
try{
Client client = new Client();
client.run();
}catch(Exception ex){ex.printStackTrace();}
}
}