Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.*;
- class K {
- public static void main(String args[]) throws Exception
- {
- BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
- DatagramSocket clientSocket = new DatagramSocket();
- //TODO: try catch if local host is not defined
- InetAddress IPAddress = InetAddress.getByName("localhost");
- byte[] sendData;
- // Full path to the file we need to GET
- System.out.print("The hostname you want to send request to: ");
- String hostname = inFromUser.readLine();
- System.out.print("The path to the file (optional): ");
- String pathname = inFromUser.readLine();
- WPSPacket WPSPacket = new WPSPacket(true, hostname, pathname);
- sendData = WPSPacket.makeRequest();
- System.out.println("\n============================");
- System.out.println("Making new WPS request with: ");
- System.out.println("============================");
- System.out.println("Hostname: " + hostname);
- System.out.println("Pathname: " + pathname);
- System.out.println("");
- DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
- clientSocket.send(sendPacket);
- System.out.println("============================");
- System.out.println("RESPONSE FROM WPS: ");
- System.out.println("============================");
- while (true) {
- // Read response from the UPD socket
- byte[] receiveData = new byte[1024];
- DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
- clientSocket.receive(receivePacket);
- WPSPacket wpsPacket = WPSPacket.readPacket(receivePacket.getData());
- // Print the response to std out
- System.out.println(wpsPacket.getContent());
- // clientSocket.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement