Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. package client.udp;
  2.  
  3. import javafx.application.Platform;
  4. import server.mvc.Controller;
  5.  
  6. import java.io.IOException;
  7. import java.net.*;
  8. import java.text.SimpleDateFormat;
  9.  
  10.  
  11. public class UDPClient {
  12.     private static final int PORT = 5000;
  13.     private static final String IP = "192.168.80.108";
  14.  
  15.  
  16.     public static void main(String[] args) throws IOException {
  17.  
  18.         server.mvc.Controller contr = new Controller();
  19.         SimpleDateFormat currentTime = new SimpleDateFormat("00:mm:ss");
  20.  
  21.  
  22.         InetAddress address = InetAddress.getByName("localHost");
  23.         DatagramSocket socket = new DatagramSocket();
  24.         int i = 0;
  25.  
  26.         while (i < 10) { //Songlänge ?
  27.             String msg = "TIME:";
  28.             msg = currentTime.format(contr.getCurrentDuration());
  29.             byte buffer[] = msg.getBytes();
  30.             DatagramPacket packet = new DatagramPacket(buffer, buffer.length, address, PORT);
  31.             socket.send(packet);
  32.  
  33.             byte answer[] = new byte[1024];
  34.             packet = new DatagramPacket(answer, answer.length);
  35.             socket.receive(packet);
  36.             System.out.println(new String(packet.getData(), 0, packet.getLength()));
  37.  
  38.             try {
  39.                 Thread.sleep(1000);
  40.             } catch (InterruptedException e) {
  41.                 e.printStackTrace();
  42.             }
  43.             i++;
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement