I'm playing with RSocket in Flutter. I've created two RSocket apis like below:
@MessageMapping("stream")
Flux<Long> numbers(){
return Flux.interval(Duration.ofSeconds(1));
}
@MessageMapping("echo")
Mono<String> echo(String text){
return Mono.just(text);
}
and trying to connect and get answer from them like:
var rsocket = await RSocketConnector.create().connect('tcp://127.0.0.1:7000');
var result = await rsocket.requestResponse!(
(Payload.fromText("message/x.rsocket.routing.v0: 4echo", "effd")));
print(result.getDataUtf8());
RSocketConnector.create()
.setupPayload(
Payload.fromText("message/x.rsocket.routing.v0: 6stream", ""))
.connect('tcp://127.0.0.1:7000')
.asStream()
.forEach((element) {
print(element);
});
.
I can call my backend using RSocket command line tool successfully like rsc --route stream tcp://localhost:7000 --stream
and it works well. However, Flutter client fails with the error below:
Unhandled Exception: SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 127.0.0.1, port = 41582
any ideas?
thanks to @Richard Head 's point. I got it to work for now by using the IP address that server gets from it's physical network interface. Also, to be able to set the correct route:
I gonna PR the Flutter RSocket for an easier way of creating routed payloads.