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)的更多相关文章

  1. 文件上传失败 -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 ...

  2. 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) ...

  3. 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 ...

  4. 【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 ...

  5. 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 ...

  6. 连接远程数据库时出现 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 ...

  7. 数据库连接出错 expected key exchange group packet form server

    数据库连接出错 expected key exchange group packet form server SSH: expected key exchange group packet form ...

  8. 粘性会话 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 ...

  9. 使用 PuTTY 时遇到错误:“expected key exchange group packet from server”

    情况 使用 PuTTY 通过 SSH 访问 ProxySG 或 Advanced Secure Gateway (ASG) 时,您会看到如下错误:"expected key exchange ...

随机推荐

  1. tomcat启动窗口中的时间与系统时间不一致

    比我的系统时间慢8个小时,应该如何设置? 产生原因是因为Tomcat中的时区设置与操作系统的时区设置不一致,通过修改Tomcat根目录下的bin文件夹中的catalina.bat文件,增加以下配置解决 ...

  2. 腾讯云服务器 - 定时备份MariaDB/MySQL

    数据库数据备份尤为重要,而我们不会人工手动去备份,这样会很麻烦,我们都是通过服务器每日自定运行来做的,设置一个定时时间即可 首先我们看一下mysqldump这个文件的位置: 可以看到目录在 /usr/ ...

  3. 哈佛大学 Machine Learning

    https://am207.github.io/2017/material.html https://am207.github.io/2017/topics.html https://am207.gi ...

  4. EF框架 对字段属性为NULL的空值处理 类型前面加上?保证EF列表读取显示数据不会报异常

    譬如: public int? FlowStatus { get; set; } public DateTime? UpdateTime { get; set; }

  5. (原创)舌尖上的c++--相逢

    引子 前些时候,我在群里出了一道题目:将变参的类型连接在一起作为字符串并返回出来,要求只用函数实现,不能借助于结构体实现.用结构体来实现比较简单: template<typename... Ar ...

  6. c++并行计算库TBB和PPL的基本用法

    并行库充分利用多核的优势,通过并行运算提高程序效率,本文主要介绍c++中两个知名的并行库,一个是intel开发的TBB,一个是微软开发的PPL.本文只介绍其基本的常用用法:并行算法和任务. TBB(I ...

  7. Asp.Net正则获取链接地址

    string html = “html代码”; Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""]?)(?< ...

  8. Eclipse报This version of the rendering library is more recent than your version of ADT ...

    http://blog.csdn.net/zhao_3546/article/details/12968295 最近使用 Help --> Check for Updates 升级了Eclips ...

  9. linux 的内核的作用和功能

    Linux内核[kernel]是整个操作系统的最底层, 它负责整个硬件的驱动,以及提供各种系统所需的核心功能, 包括防火墙机制.是否支持LVM或Quota等文件系统等等, 如果内核不认识某个最新的硬件 ...

  10. 确保安全的HTTPS(对HTTP加密的几种技术,前端面试常问)第一篇

    HTTP固然足够好,但是在安全方面有着很大隐患: 1.与服务器进行通信使用的是明文,内容可能会被窃听(HTTP协议本身并不具备加密功能,所以无法对请求和响应的内容进行加密) 2.使用HTTP协议的服务 ...