hello world entfernt; erst Konstrukt für Server in SyslogServer erstellt + gestest auf Port 5514
parent
42cf4baba4
commit
c82a06e58d
|
|
@ -1,5 +0,0 @@
|
|||
public class helloworld {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +1,39 @@
|
|||
package vs;
|
||||
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.InetAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class SyslogServer {
|
||||
public static void main(String[] args) {
|
||||
int port = 514; // Default syslog port
|
||||
int port = 5514; // Default syslog port: 514, but using 5514 to avoid permission issues
|
||||
SyslogServer server = new SyslogServer();
|
||||
server.start(port);
|
||||
}
|
||||
|
||||
public void start(int port) {
|
||||
// Implement the logic to start the syslog server and listen for incoming messages
|
||||
System.out.println("Syslog Server started on port " + port);
|
||||
// You can use a library like Netty or Java's built-in ServerSocket to handle incoming connections
|
||||
|
||||
try{
|
||||
DatagramSocket socket = new DatagramSocket(port);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
while(true){
|
||||
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
|
||||
|
||||
socket.receive(packet);
|
||||
|
||||
System.out.println("Nachricht empfangen!");
|
||||
}
|
||||
}
|
||||
|
||||
catch(IOException e){
|
||||
System.err.println("Could not start server: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue