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 ...
随机推荐
- received shard failed for shard id
1.问题描述 早上醒来发现手机有很多ES状态为red的告警,集群就前几天加了几个每天有十多亿记录的业务,当时估算过磁盘容量,应该是没有问题的,但是现在集群状态突然变成red了,这就有点懵逼了. 2.查 ...
- linux命令分享一:压缩命令
Linux操作系统中,*.zip.*.tar.*.tar.gz.*.tar.bz2.*.tar.xz.*.jar.*.7z等格式的压缩与解压 zip格式 压缩: zip -r [目标文件名].zip ...
- Android基础知识之String类使用详解
原文:http://android.eoe.cn/topic/android_sdk 字符串资源为你的应用程序提供了可以选择的文本样式和格式的文本.这里有三种类型的资源可以为你的应用程序提供字符串. ...
- [CTCI] 下一个较大元素
下一个较大元素 题目描述 现在我们有一个int数组,请你找出数组中每个元素的下一个比它大的元素. 给定一个int数组A及数组的大小n,请返回一个int数组,代表每个元素比他大的下一个元素,若不存在则为 ...
- NDK 在 Android studio如何使用(Android studio NDK)
其实这个东西入门的话.直接在官网查找demo再结合文档就能间接了解如何构建是最快捷的. 这里提供一下官网和demo的地址. 官网的NDK在Android studio的搭建:http://tools. ...
- Chrome多线程下载
https://github.com/jae-jae/camtd https://aria2.github.io/ 切换到解压目录D:\Tools\aria2-1.34.0-win-64bit中,打开 ...
- python源码安装
# mkdir /apps/Python- 解压源码包,进入源码包 [root@LB_81 Python-]# ls aclocal.m4 configure.ac install-sh Makefi ...
- Python 3.6 安装pip
1.首先python3.4以后,pip内嵌,不过使用方法是: python -m pip install django 2.如果你觉得上面的指令太长,想用旧方法使用pip,那用以下指令安装pip即可 ...
- Redis List数据类型
一.概述: 在Redis中,List类型是按照插入顺序排序的字符串链表.和数据结构中的普通链表一样,我们可以在其头部(left)和尾部(right)添加新的元素.在插入时,如果该键并不存在, ...
- centos 7 min 编译安装php5.6+nginx1.7.5 笔记
1.安装mysql请参照 centos 7 min 编译安装mysql5.6.20 笔记 2.编译安装php5.6+nginx1.7.5 2.1.安装php5.6.0 首先添加依赖应用yum inst ...