ra1u / redis-dart

fast redis protocol parser and client
MIT License
84 stars 35 forks source link

SocketException while running #20

Closed Dewsworld closed 3 years ago

Dewsworld commented 3 years ago

Hello When I run a simple code

void main() async {
  runApp(MyApp());

  RedisConnection conn = new RedisConnection();
  conn.connect('some_production_server_address',6379).then((Command command) {
    PubSub pubsub = new PubSub(command);
    pubsub.getStream().listen((message){
      Fluttertoast.showToast(
          msg: message.toString(),
          toastLength: Toast.LENGTH_SHORT,
          gravity: ToastGravity.CENTER,
          timeInSecForIosWeb: 1,
          backgroundColor: Colors.red,
          textColor: Colors.white,
          fontSize: 16.0,
      );

      // send object
      command.send_object(["PUBLISH","monkey","banana"]);
    });
  });
}

I get this error

2021-01-12 15:54:38.405 3460-3488/com.dw.flutter_redis_sample E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = some_production_server_address, port = 39609

I have added this in the manifest

<uses-permission android:name="android.permission.INTERNET"/>

Also, I am using a real device.

I am using port 6379, I am not sure why this port used for 39609 (which also changes each time I restart the app)

ra1u commented 3 years ago

Hi @Dewsworld

It looks like there is an issue with connecting to your server. Are you able to open raw connection to same server and same port from where application is running?

Dewsworld commented 3 years ago

Hi @Dewsworld

It looks like there is an issue with connecting to your server. Are you able to open raw connection to same server and same port from where application is running?

@ra1u Can you put some code to do that?

ra1u commented 3 years ago

Try to get valid Future<Socket> when calling

Socket.connect(host,port)

You can also take a look at lib/connection.dart where might be source of current issue

Dewsworld commented 3 years ago

Try to get valid Future<Socket> when calling

Socket.connect(host,port)

You can also take a look at lib/connection.dart where might be source of current issue

Here is the result from log, please look at the SocketException still persists after a few lines

[+1489 ms] I/flutter (11938): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[        ] I/flutter (11938): │ #0   main (package:flutter_redis_sample/main.dart:13:7)
[        ] I/flutter (11938): │ #1   _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:136:25)
[        ] I/flutter (11938): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
[        ] I/flutter (11938): │ 🐛 Instance of 'Future<Socket>'
[        ] I/flutter (11938): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[  +44 ms] D/libc-netbsd(11938): [getaddrinfo]: mtk hostname=test2.lalbok.services; servname=(null); netid=0; mark=0
[        ] D/libc-netbsd(11938): [getaddrinfo]: mtk ai_addrlen=0; ai_canonname=(null); ai_flags=1024; ai_family=0
[   +3 ms] D/libc-netbsd(11938): getaddrinfo: test2.lalbok.services get result from proxy gai_error = 0
[+3690 ms] D/GraphicBuffer(11938): register, handle(0x74acfb6d40) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
[ +226 ms] E/flutter (11938): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = test2.lalbok.services, port = 39824
[        ] E/flutter (11938): 
[ +154 ms] D/GraphicBuffer(11938): register, handle(0x74acfa1540) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
ra1u commented 3 years ago

It is hard to tell what is going on without more info, but if you are unable to connect to your redis server by using only Socket it is out of scope of this library. I unfortunately do not have much of experience in flutter, to be able to help you further.

Dewsworld commented 3 years ago

Okey, thanks for your effort.

Btw, here is the documents I followed to setup redis.

https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-20-04

Is there anything I am missing on server side? If you could.

ra1u commented 3 years ago

I would start start by investigating why there is "Connection refused" error message

Dewsworld commented 3 years ago

Okey, thanks again for your assistance. Will find something.