Kryonet client disconnects after send a packet to server (java)
http://stackoverflow.com/questions/25934876/kryonet-client-disconnects-after-send-a-packet-to-server-java
——————————————————————————————————————————————————————————————————
I'm doing a little MMO project and right now I'm working on the login/register system. Whenever I try to send a ClientLoginPacket, the client disconnects from the server and the packet is not received at all by the server. There is no stack trace that shows up but here is my code. Sorry it's a lot but it's all necessary:
ClientLoginPacket.java:
package net.vediogames.archipelo.networking.packets;
import net.vediogames.archipelo.networking.Networking;
public class ClientLoginPacket extends Packet{
private String username;
private String password;
private int validity = 0;
public ClientLoginPacket(String username, String password){
this.username = username;
this.password = password;
}
public String getUsername(){
return this.username;
}
public String getPassword(){
return this.password;
}
public int getLoginValidity(){
return validity;
}
public void setLoginValidity(int validity){
this.validity = validity;
}
public void send(){
Networking.sendTCP(this);
}
}
That's the login packet. The only difference with this one and the server one is the import and package declaration (its archipeloserver instead of just archipelo). As you can see, this class extends Packet, here is my Packet class:
package net.vediogames.archipelo.networking.packets;
public abstract class Packet {
protected int connectionID;
public abstract void send();
public int getConnectionId(){
return connectionID;
}
public void setConnectionID(int id){
this.connectionID = id;
}
}
All packets have a send() method that is called to send them. The way I send my packets is by doing this new ClientLoginPacket(username, password).send();. I the ClientLoginPacket class you can see that is runs Networking.sentTCP(this) to send the packet. This just runs this code in my main kryonet class Networking.java. Here is the code it uses to send packets on the client side:
public static void sendTCP(Packet object){
client.sendTCP(object);
}
In kryonet, you have to register classes before sending them. I did that but I don't know if I did it properly. Here is the exact code I used. Server:
private static void setupClasses(){
Kryo kryo = server.getKryo();
kryo.register(ClientRegisterPacket.class);
kryo.register(ClientLoginPacket.class);
System.out.println("Registered classes.");
}
Client:
public static void setupClasses(){
Kryo kryo = client.getKryo();
kryo.register(ClientRegisterPacket.class);
kryo.register(ClientLoginPacket.class);
}
What I know for sure is that I do have a connection to the server before sending a packet, I tested it with the connection listener on the server. What would my issue be? Is there something wrong with my class registration? Do both classes have to be completely identical? Thanks in advance!
p.s. sorry for throwing all that code out. I wouldn't normally do this if I didn't have to. I put the least as possible. If you need more to see how the other stuff works and to see if the issue is there, just ask me. Thanks!
1 Answer
Kryo needs a constructor without any arguments to deserialize. It looks like your ClientLoginPacket might need one? This caused an issue for me as well. It wasn't until I used the debug kryonet jars on the server and turned logging on that I got the error message that explained it.
——————————————————————————————————————————————————————————————————————————
简单来说,就是kryo乔一个无参构造函数来反序列化,否则就会丢失连接而无其他任何出错信息。
Kryonet client disconnects after send a packet to server (java)的更多相关文章
- 文件上传失败 -nginx报错 client intended to send too large body: 1331696 bytes
location / { root /data/fastdfs/data; include gzip.conf; ngx_fastdfs_module; client_max_body_size 10 ...
- Nginx报错:upstream timed out (110: Connection timed out)和client intended to send too large body【转】
nginx日志报错 2018/01/26 16:36:49 [error] 23327#0: *54953 upstream timed out (110: Connection timed out) ...
- Use Node.js DDP Client on Arduino Yun to Access Meteor Server
Use Node.js DDP Client on Arduino Yun to Access Meteor Server 概述 在Arduino Yun上安装 Node.js, 并測试与 Meteo ...
- 【MySQL】MySQL同步报错-> received end packet from server, apparent master shutdown: Slave I/O thread: Failed reading log event, reconnecting to retry报错解决和分析
[root@db-ft-db-48 ~]# tail -f /mysqlLog/beside_index_err.log 140102 20:42:26 [Note] Slave: received ...
- ERROR: Got error reading packet from server: A slave with the same server_uuid/server_id as this slave has connected to the master
centos7.5 做binlog-server,拉取主库binlog报错 问题: [root@db03-53 binlog]# mysqlbinlog -R --host=10.0.0.55 --u ...
- 连接远程数据库时出现 SSH: expected key exchange group packet from server / 2003 - Can't connect to MySQL server on 'XXX' (10038) / 1130 - Host 'XXX' is not allowed to connect to this MySQL server
昨天在自己的远程服务器上玩,把系统重装了.新装了MySQL,在本地用navicat连接的时候出了几个小问题. 问题一:SSH: expected key exchange group packet f ...
- 数据库连接出错 expected key exchange group packet form server
数据库连接出错 expected key exchange group packet form server SSH: expected key exchange group packet form ...
- 粘性会话 session affinity sticky session requests from the same client to be passed to the same server in a group of servers
Module ngx_http_upstream_module http://nginx.org/en/docs/http/ngx_http_upstream_module.html#sticky S ...
- 使用 PuTTY 时遇到错误:“expected key exchange group packet from server”
情况 使用 PuTTY 通过 SSH 访问 ProxySG 或 Advanced Secure Gateway (ASG) 时,您会看到如下错误:"expected key exchange ...
随机推荐
- js json转url参数
var json = { sh: '上海' } var params = Object.keys(json).map(function (key) { // body... return encode ...
- js获取IP地址方法总结
js代码获取IP地址的方法,如何在js中取得客户端的IP地址.原文地址:js获取IP地址的三种方法 http://www.jbxue.com/article/11338.html 1,js取得IP地址 ...
- mysql 数据类型TIMESTAMP用法
在mysql数据库中,timestamp数据类型是一个比较特殊的数据类型,可以自动在不使用程序更新情况下只要更新了记录timestamp会自动更新时间. 通常表中会有一个Create date 创建日 ...
- Xilinx Vivado的使用详细介绍(2):综合、实现、管脚分配、时钟设置、烧写
前面一篇介绍了从新建工程一直到编写代码进行行为仿真,这篇继续进行介绍. 修改器件型号 新建工程时选择过器件型号,如果新建好工程后需要修改型号,可以选择菜单Tools - Project Setting ...
- [na]IP分片抓包实验
这两点比较重要 1.IP+ICMP+DATA = 1500字节 2.ping size指定的是data的大小. 3,可以ping大包+不分片检测mtu(分片发生在出口,如果包尺寸大于接口ip mtu, ...
- HTML5学习笔记(二):HTML基础学习之二
表单 表单用来传递用户数据,多用来与后端进行数据交互. 前端: <!DOCTYPE html> <html lang="en"> <head> ...
- iOS-通讯录(无界面)
通讯录(无界面) #import "AppDelegate.h" #import <AddressBook/AddressBook.h> @interface AppD ...
- 【Linux】了解服务器的情况
Java程序大多数都部署在Unix环境,而环境的稳定性对于部署的应用至关重要,所以Java开发人员需知道了解Unix环境的命令. 系统版本 查看系统版本 [root@localhost third_p ...
- 【MyBean调试笔记】接口的使用和清理
[DEMO信息] 有问题的DEMO, 由芒果提交 [问题描述] 双击Tab页面关闭页面和插件的时候出现AV异常 [问题调试] 我们在调试的时候出现这个错误时断点停在这里 可以看到停留在这个位置@Int ...
- 碰撞器与触发器[Unity]
请看原帖,移步:Unity3d碰撞检测中碰撞器与触发器的区别 要产生碰撞必须为游戏对象添加刚体(Rigidbody)和碰撞器,刚体可以让物体在物理影响下运动.碰撞体是物理组件的一类,它要与刚体一起添加 ...