1
我正在學習一些使用KryoNet的網絡連接,並且我有這個問題,當我從服務器發送對象到客戶端時,它發送它並且我可以讀取它,但是當我發送它再次我得到這個錯誤。Kryonet在多次發送自定義對象後斷開連接
服務器:
server = new Server();
Kryo kryo = server.getKryo();
kryo.register(Command.class, new JavaSerializer());
server.start();
try {
server.bind(54555, 54777);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
客戶:
client = new Client();
Kryo kryo = client.getKryo();
kryo.register(Command.class, new JavaSerializer());
client.setKeepAliveTCP(2000);
client.start();
try {
client.connect(5000, "192.168.1.5", 54555, 54777);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
client.addListener(new Listener() {
public void connected(Connection connection){
}
public void received (Connection connection, Object object) {
if(object instanceof Command){
Command c = (Command) object;
textField.setText(Integer.toString(c.getTime()));
}
}
});
MyClass的:
}
堆棧跟蹤:
Exception in thread "Client" com.esotericsoftware.kryo.KryoException: Error during Java deserialization.
at com.esotericsoftware.kryo.serializers.JavaSerializer.create(JavaSerializer.java:42)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:758)
at com.esotericsoftware.kryonet.KryoSerialization.read(KryoSerialization.java:57)
at com.esotericsoftware.kryonet.TcpConnection.readObject(TcpConnection.java:137)
at com.esotericsoftware.kryonet.Client.update(Client.java:239)
at com.esotericsoftware.kryonet.Client.run(Client.java:317)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.StreamCorruptedException: invalid stream header: 79737200
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at com.esotericsoftware.kryo.serializers.JavaSerializer.create(JavaSerializer.java:40)
... 6 more