1

I'm trying to create a simple UDP server to handle packages from Log4j2 Socket appender but I'm getting a "java.io.StreamCorruptedException: invalid stream header: 7372003E" from the second package received on.

APPENDER:

<Socket name="Socket" host="localhost" port="9500" protocol="UDP" >
    <SerializedLayout /> 
</Socket>

SNIPPET UDP SERVER:

public void startSerialized() throws Exception {
    serverSocket = new DatagramSocket(9500);
    LogEvent logEvent = null;
    ObjectInputStream obj = null;
    ByteArrayInputStream bis = null;
    while (true) {
        try {
            receivePacket = new DatagramPacket(packet, packet.length);
            serverSocket.receive(receivePacket);
            bis = new ByteArrayInputStream(receivePacket.getData());
            obj = new ObjectInputStream(bis);
            logEvent = (LogEvent) obj.readObject();
            System.out.println(logEvent.toString());    
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            bis.close();
            obj.close();
        }           
    }
}

Any suggestion guys?

4

1 に答える 1