2

I'm trying to use Rsocket in android to communicate with the spring-boot server with kotlin. unfortunately, rsocket doesn't have good documentation. I try this code from the rsocket kotlin Github pages but I got an error.

This is my dependency:

implementation("io.rsocket.kotlin:rsocket-core:0.12.0")
implementation("io.rsocket.kotlin:rsocket-transport-ktor:0.12.0")
implementation("io.rsocket.kotlin:rsocket-transport-ktor-client:0.12.0")
implementation("io.ktor:ktor-client-cio:1.4.3")

This is my code:

CoroutineScope(Dispatchers.Main).launch {
   val client = HttpClient(CIO) {
       install(WebSockets)
       install(RSocketSupport)
   }
   val rSocket: RSocket = client.rSocket("http://demo.rsocket.io/")
   val stream: Flow<Payload> = rSocket.requestStream(Payload.Empty)
   stream.take(5).map { payload: Payload ->
       println(payload.data.readText())
   }
}

The error that I have got:

2021-06-04 17:38:49.682 31873-31873/com.example.rsockettest E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.rsockettest, PID: 31873
    java.lang.NoSuchMethodError: No static method getSeconds(I)D in class Lkotlin/time/DurationKt; or its super classes (declaration of 'kotlin.time.DurationKt' appears in /data/app/~~TL05n0pUBJZXhnzTYygaSg==/com.example.rsockettest-iWVKDxzJU4GvHrKyFG8j5A==/base.apk)
        at io.rsocket.kotlin.keepalive.KeepAlive.<init>(KeepAlive.kt:22)
        at io.rsocket.kotlin.core.RSocketConnectorBuilder$ConnectionConfigBuilder.<init>(RSocketConnectorBuilder.kt:70)
        at io.rsocket.kotlin.core.RSocketConnectorBuilder.<init>(RSocketConnectorBuilder.kt:28)
        at io.rsocket.kotlin.core.RSocketConnectorBuilderKt.RSocketConnector(RSocketConnectorBuilder.kt:112)
        at io.rsocket.kotlin.core.RSocketConnectorBuilderKt.RSocketConnector$default(RSocketConnectorBuilder.kt:111)
        at io.rsocket.kotlin.transport.ktor.client.RSocketSupport$Config.<init>(RSocketSupport.kt:30)
        at io.rsocket.kotlin.transport.ktor.client.RSocketSupport$Feature.prepare(RSocketSupport.kt:36)
        at io.rsocket.kotlin.transport.ktor.client.RSocketSupport$Feature.prepare(RSocketSupport.kt:33)
        at io.ktor.client.HttpClientConfig$install$3.invoke(HttpClientConfig.kt:77)
        at io.ktor.client.HttpClientConfig$install$3.invoke(HttpClientConfig.kt:74)
        at io.ktor.client.HttpClientConfig.install(HttpClientConfig.kt:97)
        at io.ktor.client.HttpClient.<init>(HttpClient.kt:172)
        at io.ktor.client.HttpClient.<init>(HttpClient.kt:81)
        at io.ktor.client.HttpClientKt.HttpClient(HttpClient.kt:43)
        at com.example.rsockettest.MainActivity$onCreate$1.invokeSuspend(MainActivity.kt:41)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
2021-06-04 17:38:49.722 31873-31873/com.example.rsockettest I/Process: Sending signal. PID: 31873 SIG: 9

if it's not possible to use rsocket in android, can you offer for instead for that? I want to build an application that streams data reactively.

saeed-pasa
  • 29
  • 1
  • 8
  • It is possible, but I suspect will be easier with a clean 0.13.0 release before we attempt this in a documented way. The root cause looks like changes to the kotlin duration API which is experimental. I'll try to look at this in the next week and provide an example. – Yuri Schimke Jun 15 '21 at 23:25

0 Answers0