From e92a7fe5cb975a3ceb14ab74e346d1637a66d380 Mon Sep 17 00:00:00 2001 From: civitarese Date: Fri, 20 Mar 2020 07:32:56 +0100 Subject: [PATCH] Fixed datagram packet reading --- udp/UDPClient.java | 2 +- udp/UDPServer.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/udp/UDPClient.java b/udp/UDPClient.java index 14c8caf..d55b58a 100644 --- a/udp/UDPClient.java +++ b/udp/UDPClient.java @@ -35,7 +35,7 @@ class UDPClient { /* Riceve il pacchetto dal server */ clientSocket.receive(receivePacket); - String modifiedSentence = new String(receivePacket.getData()).trim(); + String modifiedSentence = new String(receivePacket.getData(), 0, receivePacket.getLength()); System.out.println("FROM SERVER: " + modifiedSentence); clientSocket.close(); diff --git a/udp/UDPServer.java b/udp/UDPServer.java index 29f1a30..59f5b90 100644 --- a/udp/UDPServer.java +++ b/udp/UDPServer.java @@ -23,7 +23,7 @@ class UDPServer { /* Riceve un pacchetto da un client */ serverSocket.receive(receivePacket); - String sentence = new String(receivePacket.getData()); + String sentence = new String(receivePacket.getData(), 0, receivePacket.getLength()); /* Ottiene dal pacchetto informazioni sul mittente */ InetAddress IPAddress = receivePacket.getAddress(); -- 2.18.1