-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPingClient.java
More file actions
32 lines (32 loc) · 1.23 KB
/
PingClient.java
File metadata and controls
32 lines (32 loc) · 1.23 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
import java.util.*;
import java.net.*;
import java.io.*;
public class PingClient {
public static void main(String[] args) throws Exception{
Socket s= new Socket("localhost", 2156);
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
if(s.isConnected())
System.out.println("Connected to server at: "+ s.getInetAddress());
Scanner inp= new Scanner(System.in);
DataInputStream din= new DataInputStream(s.getInputStream());
DataOutputStream dout= new DataOutputStream(s.getOutputStream());
System.out.println("Enter no. of packets to send: ");
int Packets= inp.nextInt();
System.out.println("Enter address to ping: ");
String Address= br.readLine();
dout.writeUTF("P");
dout.writeInt(Packets);
dout.writeUTF("A");
dout.writeUTF(Address);
String PingProcOut= din.readUTF();
try{
do{
System.out.println("[OUTPUT]: "+ PingProcOut);
}while((PingProcOut= din.readUTF())!= null);
}catch(EOFException e){}
System.out.println("Completed Ping Process");
dout.close();
din.close();
s.close();
}
}