rocketraman
06/08/2022, 2:25 PMrequestResponse
on RSocketServer
.
I thought potentially I would create a single Transport
and then use it to configure both a ConnectionAcceptor
for the server as well as attach it to an RSocketConnector
. However, since we have different ServerTransport
and ClientTransport
types, this doesn't seem possible either.
What am I missing?rocketraman
06/08/2022, 2:42 PMOleg Yukhnevich
06/08/2022, 3:20 PMOleg Yukhnevich
06/08/2022, 3:24 PMrequester
from ConnectionAcceptor
+ you can get it on client side as result of calling connect
but configuring of ConnectionAcceptor
is different for client and server
for server you provide it on calling bind
but for client, you need to provide it during building RSocketConnector
so like:
RSocketConnector {
acceptor {
//you can access requester here and return responder
}
}
Oleg Yukhnevich
06/08/2022, 3:27 PMOleg Yukhnevich
06/08/2022, 3:29 PMOleg Yukhnevich
06/08/2022, 3:29 PMrocketraman
06/08/2022, 3:34 PMconnect
is clear. Server-side is unclear. I pass the acceptor to bindIn
, but the logic that does accept
in server-side is called for me, so how do I obtain the RSocket
?
BTW: what do you want to achieve in the end?So basically I have some server-to-server communication. Both sides periodically need to initiate some request/response or fire-forget to the other side. Obviously one side has to be the client and the other side the server from a TCP perspective, but I thought the bi-di nature of the rsocket protocol would allow me to abstract away that detail and allow either side to easily use an RSocket to send/receive messages.
rocketraman
06/08/2022, 3:36 PMOleg Yukhnevich
06/08/2022, 3:36 PMrequester: RSocket
from ConnectionAcceptorContext
, or I miss something?Oleg Yukhnevich
06/08/2022, 3:38 PMRSocketServer().bind(transport) {
val rSocket: RSocket = requester //comes from ConnectionAcceptorContext
launch {
delay(1000)
requester.requestResponse(somePayload)
}
createResponder()
}
rocketraman
06/08/2022, 3:42 PMConnectionAcceptor
definition. Would you use some kind of call-back function to save the requestor
RSocket elsewhere for re-use? How would one track the state of these rsockets i.e. connected/disconnected, etc?Oleg Yukhnevich
06/08/2022, 3:53 PMcoroutineContext
of RSocket
requester - but for this I also have some prototypes to improve (also you can keep track an issue https://github.com/rsocket/rsocket-kotlin/issues/205)
can you also look at https://github.com/rsocket/rsocket-kotlin/blob/master/samples/chat/server/src/commonMain/kotlin/acceptor.kt#L45 - why it's not acceptable for you?
I don't know your specifics, but I don't understand why you can't just launch coroutine inside acceptor (like in my previous comment) and put server code there
or you can even just create RSocket class which accepts requester and provide it as responder
class ServerRSocket(private val requester: RSocket): RSocket {
//you can also launch some coroutines here
override fun requestResponse(payload: Payload): Payload {
//here comes responder logic, and you can call requester here
}
}
or if you want to get symmetric API for server, like after calling bind
you will receive RSocket instance of requester? If so, why?rocketraman
06/08/2022, 4:10 PMrequestor
. I can create some channels/callbacks/flows or something to communicate between these external triggers and that code in the acceptor but that's all significantly more code than just being able to obtain a reference to the connected RSocket's directly and use them.Oleg Yukhnevich
06/08/2022, 4:13 PMval serverRequester: RSocket = RSocketServer().bind(transport) { createServerResponder() }
so it suspend until first connection appears and you can just use this requester everywhere in your app, right?rocketraman
06/08/2022, 4:20 PMRSocketClients
wrapper which would allow access to all clients (maybe along with some state information as per issue 205).rocketraman
06/08/2022, 4:21 PMOleg Yukhnevich
06/08/2022, 4:33 PM