Fertig
parent
16221f3c29
commit
7d91bb4d3c
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue