|
@ -12,6 +12,8 @@ class UDPServer { |
|
|
byte[] receiveData = new byte[1024]; |
|
|
byte[] receiveData = new byte[1024]; |
|
|
byte[] sendData = new byte[1024]; |
|
|
byte[] sendData = new byte[1024]; |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("UDP Server started. Waiting for incoming requests..."); |
|
|
|
|
|
|
|
|
while (true) { |
|
|
while (true) { |
|
|
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); |
|
|
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); |
|
|
serverSocket.receive(receivePacket); |
|
|
serverSocket.receive(receivePacket); |
|
@ -19,8 +21,9 @@ class UDPServer { |
|
|
|
|
|
|
|
|
InetAddress IPAddress = receivePacket.getAddress(); |
|
|
InetAddress IPAddress = receivePacket.getAddress(); |
|
|
int clientSrcPort = receivePacket.getPort(); |
|
|
int clientSrcPort = receivePacket.getPort(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("Received request from client " + IPAddress + ":" + clientSrcPort + " generating response..."); |
|
|
|
|
|
|
|
|
String capitalizedSentence = sentence.toUpperCase(); |
|
|
String capitalizedSentence = sentence.toUpperCase(); |
|
|
sendData = capitalizedSentence.getBytes(); |
|
|
sendData = capitalizedSentence.getBytes(); |
|
|
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, clientSrcPort); |
|
|
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, clientSrcPort); |
|
|