跳到主要内容

TCP 启动游戏对外服

介绍

在 ioGame 中,将 WebSocket 改为 TCP 的连接方式是简单的。 只需将连接方式设置为 ExternalJoinEnum.TCP 就可以了。

public ExternalServer createExternalServer() {
...
DefaultExternalServer
.newBuilder(externalCorePort)
.externalJoinEnum(ExternalJoinEnum.TCP);

return builder.build();
}

Example Source Code

see https://github.com/iohao/ioGameExamples

path : SimpleExample/example/example-for-tcp-socket

  • DemoTcpSocketApplication
  • DemoSocketClient

TCP 编解码

see TcpExternalCodec

提示

TCP 编解码在头多加了 4 个字节,表示消息体的大小。

+--------+----------------+
| int | Actual Content |
| 0x000? | ExternalMessage|
+--------+----------------+