Guest User

Untitled

a guest
Apr 27th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.*;
  3. import java.nio.charset.*;
  4. import java.util.Scanner;
  5.  
  6. class TelloClient
  7. {
  8. public static void main(String args[]) throws Exception
  9. {
  10. String sentence = "";
  11. String responseSentence= "";
  12. Scanner scanner = new Scanner(System.in, "UTF-8");
  13. DatagramSocket clientSocket = new DatagramSocket();
  14.  
  15. InetAddress IPAddress = InetAddress.getByName("tello");
  16.  
  17. System.out.println("Connessione al Tello effettuata.");
  18.  
  19. byte[] sendData = null;
  20. byte[] receiveData = new byte[256];
  21.  
  22. while (!sentence.equals("bye")){
  23. System.out.print("Inserisci comando: ");
  24. sentence = scanner.nextLine();
  25.  
  26. sendData = sentence.getBytes();
  27. DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 8889);
  28. clientSocket.send(sendPacket);
  29.  
  30. DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
  31. clientSocket.receive(receivePacket);
  32.  
  33. responseSentence = new String(receivePacket.getData(), StandardCharsets.UTF_8);
  34.  
  35. System.out.println("FROM Tello:" + responseSentence);
  36. }//end while
  37.  
  38. clientSocket.close();
  39. }
  40. }
Add Comment
Please, Sign In to add comment