title: Can we make a UDP call to REST service
body: <p>I have a REST endpoint and I want to access it using UDP for example Java Datagram. I know its not a best practice to try even but my recent project I have some hardware limitations. Hardware can make UDP calls only and my existing services are over REST i.e. HTTP/HTTPS.<br>
  I am looking for any way I can reuse my existing services. I have tried following code but received <code>UnknownHostException</code>.</p>
  
  <pre><code>public class UDPClinet {
      public static void main(String[] args) {
          String hostname = "https://jsonplaceholder.typicode.com/posts/1";
          int port = 80;
          try {
              InetAddress address = InetAddress.getByName(hostname);
              DatagramSocket socket = new DatagramSocket();
              while (true) {
                  DatagramPacket request = new DatagramPacket(new byte[1], 1, address, port);
                  socket.send(request);
                  byte[] buffer = new byte[512];
                  DatagramPacket response = new DatagramPacket(buffer, buffer.length);
                  socket.receive(response);
                  String quote = new String(buffer, 0, response.getLength());
                  System.out.println(quote);
                  System.out.println();
                  Thread.sleep(10000);
              }
          } catch (SocketTimeoutException ex) {
              System.out.println("Timeout error: " + ex.getMessage());
              ex.printStackTrace();
          } catch (IOException ex) {
              System.out.println("Client error: " + ex.getMessage());
              ex.printStackTrace();
          } catch (InterruptedException ex) {
              ex.printStackTrace();
          }
      }
  }
  </code></pre>