Socket.D - Java 开发
开发,主要是对 “会话” 与 “监听器” 接口的应用组合!另外,客户端使用单连接即可:
//如果不能连接正常返回(由心跳尝试不断连接)
ClientSession session = SocketD.createClient("sd:ws://127.0.0.1:8602/?u=a&p=2")
.open();
//如果不能连接则异常
ClientSession session = SocketD.createClient("sd:ws://127.0.0.1:8602/?u=a&p=2")
.openOrThow();
目前 Java 的传输适配有(提醒:bio 的适配,不适合做服务端):
适配 | 基础传输协议 | 支持端 | 安全 | 备注 |
---|---|---|---|---|
org.noear:socketd-transport-java-kcp | sd:kcp | c,s | / | nio |
org.noear:socketd-transport-java-tcp | sd:tcp | c,s | ssl | bio(86kb) |
org.noear:socketd-transport-java-udp | sd:udp | c,s | / | bio(86kb) |
org.noear:socketd-transport-java-websocket | sd:ws, sd:wss | c,s | ssl | nio(217kb) |
org.noear:socketd-transport-netty | sd:tcp, sd:udp | c,s | ssl | nio(2.5mb) |
org.noear:socketd-transport-smartsocket | sd:tcp | c,s | ssl | aio(254kb) |
项目中引入任何 “一个” 或 “多个” 传输适配包即可,例如:
- maven
<dependency>
<groupId>org.noear</groupId>
<artifactId>socketd-transport-netty</artifactId>
<version>2.5.11</version>
</dependency>
- gradle
implementation("org.noear:socketd-transport-java-kcp:2.5.11")