几天来我一直在尝试找出问题所在,改变事物等,但无济于事。
尝试使用我的三星设备调试客户端时,在 android studio 中出现以下错误:
com.esotericsoftware.kryonet.KryoNetException: Incorrect number of bytes (1 remaining) used to deserialize object: null
at com.esotericsoftware.kryonet.TcpConnection.readObject(TcpConnection.java:146)
at com.esotericsoftware.kryonet.Client.update(Client.java:255)
at com.esotericsoftware.kryonet.Client.run(Client.java:338)
at java.lang.Thread.run(Thread.java:856)
我认为它使用相同的 java 版本,并且我注册的类完全相同。客户端:
Client client = new Client();
Kryo kryo = client.getKryo();
kryo.register(SomeRequest.class);
kryo.register(SomeResponse.class);
client.start();
try{
client.connect(5000, "10.0.0.4", 31055, 32055);
}catch (IOException e) {
throw new GdxRuntimeException(e);
}
SomeRequest request = new SomeRequest();
request.text = "Here is the request";
client.sendTCP(request);
client.addListener(new Listener() {
public void received (Connection connection, Object object) {
if (object instanceof SomeResponse) {
SomeResponse response = (SomeResponse)object;
System.out.println(response.text);
}
}
});
服务器端:
Server server = new Server();
Kryo kryo = server.getKryo();
kryo.register(SomeRequest.class);
kryo.register(SomeResponse.class);
server.start();
System.out.println("server started");
server.bind(31055, 32055);
server.addListener(new Listener(){
public void connected(Connection connection){
System.out.println("connect");
}
public void received (Connection connection, Object object) {
if (object instanceof SomeRequest) {
SomeRequest request = (SomeRequest)object;
System.out.println(request.text);
SomeResponse response = new SomeResponse();
response.text = "Thanks";
connection.sendTCP(response);
}
}
});
}
类:
class SomeRequest{
public String text;
}
class SomeResponse {
public String text;
}
正如你可以看到它非常基本的代码,但连接是一场噩梦。请帮忙!!我在 android studio 中创建客户端,在 eclipse 中创建服务器。这可能是问题的原因吗?这是我能够怀孕的唯一合乎逻辑的原因。我该如何解决?