我遵循了这个 Youtube 教程,涵盖了 Kryonet 的基础知识。
基本上它是一个 Kryonet Hello World,它解释了如何设置一个基本的服务器和一个客户端,允许客户端向服务器发送数据包并进行非常基本的通信。
源代码的链接。服务器和客户端都具有相同的数据包类。
我可以让服务器运行,客户端要求 IP 连接。但是,当我输入 IP 时,客户端在连接后立即终止。
客户端输出:
00:03 INFO: Connecting: /127.0.0.1:54555
00:03 INFO: [kryonet] Connection 1 connected: /127.0.0.1
00:03 INFO: [CLIENT] You have connected.
BUILD SUCCESSFUL (total time: 3 seconds)
服务器命令行日志:
00:00 INFO: [kryonet] Server opened.
00:04 DEBUG: [kryonet] Port 54555/TCP connected to: /127.0.0.1:53217
00:04 DEBUG: [kryo] Write: RegisterTCP
00:04 INFO: [kryonet] Connection 1 connected: /127.0.0.1
00:04 INFO: [SERVER] Someone has connected.
00:04 DEBUG: [kryonet] Connection 1 update: Se ha forzado la interrupcion de una
conexion existente por el host remoto
00:04 INFO: [SERVER] Someone has disconnected.
00:04 INFO: [kryonet] Connection 1 disconnected.
似乎系统关闭了 TCP 连接,但我真的不知道。我必须在 Windows 或/和路由器中启用某些东西以允许 Kryonet 通信吗?
有人能发现问题吗?提前致谢。
命令行日志中以西班牙语显示的行类似于“远程主机已强制中断现有连接”。
在 user1816380 建议后编辑:
大多数时候它仍然显示原始错误,但有时您会看到:
00:00 INFO: [kryonet] Server opened.
00:07 DEBUG: [kryonet] Port 54555/TCP connected to: /127.0.0.1:50787
00:07 DEBUG: [kryo] Write: RegisterTCP
00:07 INFO: [kryonet] Connection 1 connected: /127.0.0.1
00:07 INFO: [SERVER] Someone has connected.
00:07 DEBUG: [kryo] Read: Packet0LoginRequest
00:07 DEBUG: [kryonet] Connection 1 received TCP: Packet0LoginRequest
00:07 DEBUG: [kryo] Write: Packet1LoginAnswer
00:07 DEBUG: [kryonet] Connection 1 sent TCP: Packet1LoginAnswer (6)
00:07 DEBUG: [kryonet] Connection 1 update: Se ha forzado la interrupcion de una
conexion existente por el host remoto
00:07 INFO: [SERVER] Someone has disconnected.
00:07 INFO: [kryonet] Connection 1 disconnected.