-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTCPClient.java
More file actions
34 lines (26 loc) · 1.11 KB
/
TCPClient.java
File metadata and controls
34 lines (26 loc) · 1.11 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
import java.io.*;
import java.net.*;
public class TCPClient {
public static void main(String[] args) {
String serverName = "localhost";
int port = 6666;
try{
System.out.println("\n\nConnecting to " + serverName + " on port " + port);
Socket client = new Socket(serverName, port);
System.out.println("\n\nJust connected to " + client.getRemoteSocketAddress());
System.out.print("\n\n\nEnter Employee ID : ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int idInput = Integer.parseInt(br.readLine());
OutputStream outToServer = client.getOutputStream();
DataOutputStream out = new DataOutputStream(outToServer);
out.writeInt(idInput);
InputStream inFromServer = client.getInputStream();
DataInputStream in = new DataInputStream(inFromServer);
System.out.print("\n\n\n\n\nBelow details were returned by the server : "+in.readUTF());
client.close();
}
catch(Exception e){
System.out.println("Client Side problem : "+e);
}
}
}