Helloworld
其它内容参考 Java 开发(接口与包都一样)
- 导入包
implementation("org.noear:socketd-transport-netty:2.5.12")
- 代码演示(使用 kotlin 演示)
//打开客户端会话(以 url 形式打开)
val session = SocketD.createClient("sd:tcp://127.0.0.1:8602/?token=1b0VsGusEkddgr3d")
.open()
val message = StringEntity("Hello wrold!").metaPut("user", "noear")
//发送
session.send("/demo", message)
//发送并请求(且,等待一个答复)
val reply = session.sendAndRequest("/demo", message)
System.out.println(reply)
//发送并订阅(且,接收零个或多个答复流)
session.sendAndSubscribe("/demo", message) { reply ->
//打印
System.out.println(reply)
}