Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.net.*;
  4.  
  5. class K {
  6.     public static void main(String args[]) throws Exception
  7.     {
  8.         BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
  9.         DatagramSocket clientSocket = new DatagramSocket();
  10.         //TODO: try catch if local host is not defined
  11.         InetAddress IPAddress = InetAddress.getByName("localhost");
  12.  
  13.         byte[] sendData;
  14.         // Full path to the file we need to GET
  15.         System.out.print("The hostname you want to send request to: ");
  16.         String hostname = inFromUser.readLine();
  17.         System.out.print("The path to the file (optional): ");
  18.         String pathname = inFromUser.readLine();
  19.  
  20.         WPSPacket WPSPacket = new WPSPacket(true, hostname, pathname);
  21.         sendData = WPSPacket.makeRequest();
  22.         System.out.println("\n============================");
  23.         System.out.println("Making new WPS request with: ");
  24.         System.out.println("============================");
  25.         System.out.println("Hostname: " + hostname);
  26.         System.out.println("Pathname: " + pathname);
  27.         System.out.println("");
  28.  
  29.         DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
  30.         clientSocket.send(sendPacket);
  31.         System.out.println("============================");
  32.         System.out.println("RESPONSE FROM WPS: ");
  33.         System.out.println("============================");
  34.  
  35.         while (true) {
  36.             // Read response from the UPD socket
  37.             byte[] receiveData = new byte[1024];
  38.             DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
  39.             clientSocket.receive(receivePacket);
  40.             WPSPacket wpsPacket = WPSPacket.readPacket(receivePacket.getData());
  41.             // Print the response to std out
  42.             System.out.println(wpsPacket.getContent());
  43. //            clientSocket.close();
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement