amazon-web-servicessocket.ioaws-application-load-balancer

How to use AWS ALB for socketio connecting from mobile app (flutter)?


I have one EC2 instance exposing port 443 for normal web https and port 1605 for https socketio (a service in typescript using express + socketio "socket.io": "^4.7.5",

I use in flutter this library socket_io_client: ^2.0.3+1 to connect to my socketio server in the url https://example.com:1605

This setup was working fine before I started to use ALB.

Before using the alb

I had my domain configured to point to the EIP of my EC2 instance. I had one tcp port 1605 rule in the EC2 security group. I specified in the flutter code as socketio url https://example.com:1605 and worked great, could send and receive messages.

After I used alb

I introduced the ALB and configured my domain A record to point to the ALB DNSs (alias record in Route53).

I can access the web and api totally fine.

I cannot connect anymore to socketio via the mobile app in port 1605.

I have:

I don't know how to troubleshoot further.

PS: I am using https protocol in the AWS ALB listener rule because I cannot see any plain TCP (I know that is part of NLB but I read online that also ALB supports websockets and socketio so I want to learn how)


Solution

  • I switched to using the web protocol and not directly the port 1605 and this worked smoothly.

    I don't know if there is any performance impact yet with this approach.

    I switched in flutter code the url from https://example.com:1605 to https://example.com and then via polling and websocket upgrade it worked

    PS: As I mentioned in the EC2 approach I was using directly the socketio port instead of the express web endpoint.