dart-lang / web_socket_channel

StreamChannel wrappers for WebSockets.
https://pub.dev/packages/web_socket_channel
BSD 3-Clause "New" or "Revised" License
419 stars 109 forks source link

Can not connect to another channel with same domain but different param #284

Closed phuocbitmark closed 1 year ago

phuocbitmark commented 1 year ago

Hi, I'm working on an app that have chat feature. When i enter to a chat room i connect to channel url = baseUrl?param1=...&param2=... _websocketChannel = IOWebSocketChannel.connect(url, header... When i leave chat i close it _websocketChannel.sink.close();

It works if i only use one chat room. But if i leave the first room and enter another room, which mean same baseUrl but different param, i couldn't connect. It appears to me that when i enter the second chat room, it used the first room's param to connect. The url somehow was cached. I have to kill app and open it again to use different param. We check our backend side code, and it doesn't seem to be backend problem.

Do you know what the root cause and how to fix it? Thank you

PS: i'm using version ^2.1.0, even i upgrade, i still experience the same problem

TheGlorySaint commented 1 year ago

@phuocbitmark What is your print output of the url when you connect to the second room? Is this the same as the first?

natebosch commented 1 year ago

I'm not aware of any caching that would exhibit this behavior in package:web_socket_channel. We flow the arguments fairly directly to WebSocket.connect. https://api.dart.dev/stable/3.1.3/dart-io/WebSocket/connect.html

@brianquinlan - is there any caching/reuse by Uri in the VM implementation?

@phuocbitmark - can you provide a minimal code sample that generates this behavior?

natebosch commented 1 year ago

I tried making two clients connected to Uris which differ only by a query parameter, and I cannot reproduce any unexpected behavior.

@phuocbitmark - could the reuse be happening in your implementation?

phuocbitmark commented 1 year ago

Thank you for your time. I had resolved the problem, and it's my fault, i didn't realize that the signature in my header was cached. Sorry you guys.