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. svm工具箱快速入手简易教程

    首先svm是用来做分类的,是一种有监督的分类器. 什么是有监督的呢?就是说在你给我一个数据集让我做分类之前.我已经有一些经验数据了.即要先进行学习,再进行分类. 这里就有了训练集和测试集.先用训练集来 ...

  2. MySQL创建用户与授权方法实例精讲

    MySQL中创建用户与授权的实现方法. 运行环境:widnows xp professional + MySQL5.0 一, 创建用户: 命令:CREATE USER 'username'@'host ...

  3. [nginx]站点目录及文件访问控制

    nginx.conf配置文件 http ->多个server -> 多个location ->可限制目录和文件访问(根据i扩展名限制或者rewrite.) 根据目录或扩展名,禁止用户 ...

  4. 【Unity】2.9 光源(Lights)

    分类:Unity.C#.VS2015 创建日期:2016-03-31 一.简介 光源 (Lights) 是每个场景的重要组成部分.网格和纹理决定了场景的形状和外观,而光源则决定了三维环境的颜色和氛围. ...

  5. windows 内存管理的几种方式及其优缺点

    windows 内存管理方式主要分为:页式管理,段式管理,段页式管理. 页式管理的基本原理是将各进程的虚拟空间划分为若干个长度相等的页:页式管理把内存空间按照页的大小划分成片或者页面,然后把页式虚拟地 ...

  6. pandas数组(pandas Series)-(4)NaN的处理

    上一篇pandas数组(pandas Series)-(3)向量化运算里说到,将两个 pandas Series 进行向量化运算的时候,如果某个 key 索引只在其中一个 Series 里出现,计算的 ...

  7. Ctex中WinEdt经常弹出注册小窗口 解决办法

    使用WinEdt 7避免跳出“注册对话框” 在options菜单下点options…,在advanced configuration  =>  Event Handlers  下点Exit, 在 ...

  8. 【教程】linux下安装Google Chrome

    google chrome       google浏览器一直都是深受大家喜爱的一个浏览器,而且其跨平台性比较好,这对于书签同步来说是非常重要的.但是在linux下,默认的是火弧浏览器,而google ...

  9. 多媒体文件格式之ASF

    [时间:2016-06] [状态:Open] ASF,全称Advanced Systems Format,是由微软提出的开放封装格式标准.ASF是微软公司Windows Media的核心.这是一种包含 ...

  10. 解决chrome extension无法下载的问题

    由于GFW把谷歌应用商店给屏蔽了,下载chrome扩展变得很困难. 我使用的是版本30.0.1599.101 m. 那么你需要做的第一个处理是,修改host文件,保证chrome应用商店可以登录.如下 ...