我正在尝试创建一个简单的 UDP 服务器来处理来自 Log4j2 Socket appender 的包,但是我从收到的第二个包中得到了“java.io.StreamCorruptedException:无效流标头:7372003E”。
附加器:
<Socket name="Socket" host="localhost" port="9500" protocol="UDP" >
<SerializedLayout />
</Socket>
片段 UDP 服务器:
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();
}
}
}
有什么建议吗?