Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.*;
- import java.util.*;
- public class PingClient
- {
- public static void main(String[] args)
- {
- int size = 64;
- int port;
- byte[] sendBuf = new byte[size];
- Scanner scan = new Scanner(System.in);
- if(args.length != 1)
- {
- System.out.println("For use with PingServer Client");
- return;
- }
- System.out.println("Enter packet size(default = 64): ");
- size = scan.nextInt();
- System.out.println("Enter server Port(default = 4445): ");
- port = scan.nextInt();
- DatagramSocket socket = new DatagramSocket();
- byte[] buf = new byte[size];
- InetAddress address = InetAddress.getByName(args[0]);
- DatagramPacket packet = new DatagramPacket(buf, buf.length, address, port);
- socket.send(packet);
- packet = new DatagramPacket(buf, buf.length);
- socket.receive(packet);
- String received = new String(packet.getData(), 0, packet.getLength());
- System.out.println(received);
- }
- }
Add Comment
Please, Sign In to add comment