Browse Source

clarified meaning of delay in UDPTimeCounterClient

master
Sebastian Rieger 7 years ago
parent
commit
a17960ffc0
  1. 59
      VerteilteSysteme-Examples/src/verteiltesysteme/socket/simple/UDPServer.java
  2. 2
      VerteilteSysteme-Examples/src/verteiltesysteme/socket/timecounter/UDPTimeCounterClient.java

59
VerteilteSysteme-Examples/src/verteiltesysteme/socket/simple/UDPServer.java

@ -1,29 +1,30 @@
/* Angelehnt an Kurose/Ross Computernetzwerke (bis 5e Java, ab 6e Python) */
package verteiltesysteme.socket.simple;
import java.net.*;
class UDPServer {
public static void main(String args[]) throws Exception {
int udpPort = 36037;
@SuppressWarnings("resource")
DatagramSocket serverSocket = new DatagramSocket(udpPort);
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
while (true) {
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
String sentence = new String(receivePacket.getData(), 0, receivePacket.getLength());
InetAddress IPAddress = receivePacket.getAddress();
int clientSrcPort = receivePacket.getPort();
String capitalizedSentence = sentence.toUpperCase();
sendData = capitalizedSentence.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, clientSrcPort);
serverSocket.send(sendPacket);
}
}
}
/* Angelehnt an Kurose/Ross Computernetzwerke (bis 5e Java, ab 6e Python) */
package verteiltesysteme.socket.simple;
import java.net.*;
class UDPServer {
public static void main(String args[]) throws Exception {
int udpPort = 36037;
@SuppressWarnings("resource")
DatagramSocket serverSocket = new DatagramSocket(udpPort);
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
while (true) {
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
String sentence = new String(receivePacket.getData(), 0, receivePacket.getLength());
InetAddress IPAddress = receivePacket.getAddress();
int clientSrcPort = receivePacket.getPort();
String capitalizedSentence = sentence.toUpperCase();
sendData = capitalizedSentence.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, clientSrcPort);
serverSocket.send(sendPacket);
}
}
}

2
VerteilteSysteme-Examples/src/verteiltesysteme/socket/timecounter/UDPTimeCounterClient.java

@ -68,7 +68,7 @@ class UDPTimeCounterClient {
// Delay als Zeit zwischen timestampSent und timestampEnd berechnen und
// ausgeben
delay = timestampEnd - timestampStart;
System.out.println("Delay = " + delay + " ms");
System.out.println("Übertragungsdauer = " + delay + " ms");
System.out.println(System.lineSeparator());
// Antwort vom Server auswerten und ausgeben

Loading…
Cancel
Save