dart-lang / web_socket_channel

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

Any problems with WebSocketChannel.connect under iOS 17.5 beta (or earlier)? #350

Closed farr64 closed 1 month ago

farr64 commented 2 months ago

I ran into an inconsistent behavior

WebSocketChannel.connect works perfectly on most of my test phones:

However, on the latest and greatest iPhone 15 Pro under iOS 17.5 beta, WebSocketChannel.connect fails consistently with a time out (which I detect via try/catch for await on .ready).

Curiously, this same iPhone connects perfectly to the WebSocket server using the exact same Flutter app as a WebApp (served by a remote Apache server) and as the corresponding PWA. The "native" version of the Flutter app fails with this iPhone but the "not-so-native" WebApp and PWA versions of the same Flutter app work perfectly withWebSocketChannel.connect. Beats me.

Perhaps this failure also happens on other recent versions of iOS, whether beta or not, but I just started noticing this behavior. At first, I thought I had introduced a subtle bug in my app but then I became suspicious

While searching for clues, I saw this on Apple's Developer forums:

https://forums.developer.apple.com/forums/thread/685403

They mention iOS 15, so this misbehavior might be older than I suspect.

Has anyone here ran into this inconsistent behavior? Any recommended work arounds for Flutter's web_socket_channel ?

Thanks.

brianquinlan commented 1 month ago

@farr64 you could try using package:cupertino_http CupertinoWebSocket with AdapterWebSocketChannel.

farr64 commented 1 month ago

Thanks @brianquinlan

I'll investigate those approaches.

In the meantime, I discovered something that might be of general interest: Local network access vs. remote network access.

Both of these servers are on our local network:

The Flutter app running on older iPhones can access both of these servers when connected via Wi-Fi to our local network (and they can also access them from outside of our local network).

The exact same Flutter app running on my new iPhone 15 Pro under iOS 17.5 beta can't access either of these servers when connected via Wi-Fi to my local network.

Out of curiosity, I decided to disabled Wi-Fi access and BINGO: The Flutter app running on my new iPhone 15 Pro under iOS 17.5 beta successfully accesses both of these servers from outside of our local network.

Somehow, something somewhere (in some new iOS hardware and/or software configuration) is not permitting the Flutter app's web_socket_channel and webview_flutter to access servers on the local network.

That "something somewhere" (in some new iOS hardware and/or software configuration) happily permits the Flutter app's web_socket_channel and webview_flutter to access remote servers.

Any ideas?

Fortunately, as developers, the members of my team are the only ones who will run into these challenges, because our customers are not within our local network.

I'm the first team member to run into this, so I'm the canary in the coal mine. It's a bit of a pain but, now that I found out a work-around, I can live with this annoyance. Not ideal, but endurable.

It would be useful to figure out:

Thanks for any suggestions.

farr64 commented 1 month ago

I just upgraded my version of iOS 17.5 beta to the official iOS 17.5 (21F79) and WebSocketChannel.connect now works perfectly and it has no problem accessing the WebSocket server on our local network.

Beats me.

Thanks for the suggestions, @brianquinlan