Socket.D v2.5.9

Helloworld

</> markdown

其它内容参考 Java 开发(接口与包都一样)


  • 导入包
implementation("org.noear:socketd-transport-java-tcp:2.5.9")
implementation("com.github.tony19:logback-android:3.0.0")
  • 代码演示(使用 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)
Log.i(reply.toString())

//发送并订阅(且,接收零个或多个答复流)
session.sendAndSubscribe("/demo", message) { reply ->
    //打印
    Log.i(reply.toString())
}