From 7d91bb4d3cfe4e991f05e3a5cab38366cc68776b Mon Sep 17 00:00:00 2001 From: 2123000 <2123000@stud.hs-mannheim.de> Date: Fri, 12 Apr 2024 12:44:15 +0200 Subject: [PATCH] Fertig --- .../hs_mannheim/ffi/vs/syslog/model/SyslogClient.java | 10 +++++++--- .../hs_mannheim/ffi/vs/syslog/model/SyslogServer.java | 7 +++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Service-Discovery/src/de/hs_mannheim/ffi/vs/syslog/model/SyslogClient.java b/Service-Discovery/src/de/hs_mannheim/ffi/vs/syslog/model/SyslogClient.java index 8360fa3..b2405e8 100644 --- a/Service-Discovery/src/de/hs_mannheim/ffi/vs/syslog/model/SyslogClient.java +++ b/Service-Discovery/src/de/hs_mannheim/ffi/vs/syslog/model/SyslogClient.java @@ -3,16 +3,17 @@ package de.hs_mannheim.ffi.vs.syslog.model; import java.io.IOException; import java.net.*; +import de.hs_mannheim.ffi.vs.syslog.model.SyslogMessage.Message; + public class SyslogClient { private static final int SYSLOG_PORT = 514; private static final int DISCOVERY_PORT = 8888; - private static final int TIMEOUT = 2000; public static void main(String[] args) throws SocketException { - String message = "Test message from SyslogClient"; + String message = "Test Test Test"; try { sendToSyslogPort(message); @@ -29,7 +30,10 @@ public class SyslogClient { InetAddress serverAddress = InetAddress.getLocalHost(); DatagramPacket packet = new DatagramPacket(message.getBytes(), message.getBytes().length, serverAddress, SYSLOG_PORT); + // Warten auf die Antwort vom Server socket.send(packet); + System.out.println("Nachricht zurückerhalten von " + packet.getAddress()); + socket.close(); } @@ -45,7 +49,7 @@ public class SyslogClient { byte[] responseBuffer = new byte[1024]; DatagramPacket responsePacket = new DatagramPacket(responseBuffer, responseBuffer.length); socket.receive(responsePacket); - System.out.println("Received response from SyslogServer: " + responsePacket.getAddress()); + System.out.println("Nachricht zurückerhalten von " + responsePacket.getAddress() + " Portnummer " + responsePacket.getPort()); socket.close(); } diff --git a/Service-Discovery/src/de/hs_mannheim/ffi/vs/syslog/model/SyslogServer.java b/Service-Discovery/src/de/hs_mannheim/ffi/vs/syslog/model/SyslogServer.java index 1932d56..35b2f47 100644 --- a/Service-Discovery/src/de/hs_mannheim/ffi/vs/syslog/model/SyslogServer.java +++ b/Service-Discovery/src/de/hs_mannheim/ffi/vs/syslog/model/SyslogServer.java @@ -6,7 +6,7 @@ import java.net.DatagramSocket; public class SyslogServer { private static final int SYSLOG_PORT = 514; private static final int DISCOVERY_PORT = 8888; - private static final int MAX_MESSAGE_LENGTH = 1024; + private static final int MAX_MESSAGE_LENGTH = 512; public void startServer() { try{ @@ -27,13 +27,13 @@ public class SyslogServer { processDiscovery(discoveryPacket); } } catch (IOException e) { - System.err.println(e); + e.printStackTrace(); } } private void processMessage(DatagramPacket packet) { - System.out.println("Message received from " + packet.getAddress() + ": " + new String(packet.getData()).trim()); + System.out.println("Nachricht bekommen von " + packet.getAddress() + ": " + new String(packet.getData(), 0, packet.getLength())); } private void processDiscovery(DatagramPacket packet) { @@ -49,7 +49,6 @@ public class SyslogServer { } } - //Bind nicht verwenden public static void main(String[] args) { SyslogServer server = new SyslogServer();