从 Dart/Flutter 到 Google Cloud Run 的 WebSocket 连接失败

问题描述

是否有人成功地在 Flutter/Dart 客户端和在 Google Cloud Run 上运行的服务器之间使用 WebSocket 连接?

正是这个组合对我来说失败了。

客户端与本地主机上的同一台服务器一起工作。
一个客户端使用 Cloud Run 上的同一台服务器。

我试图找出问题的原因,所以我用 Dart 和 Python 的客户端和 Java 和 Python 的服务器创建了一个完整的错误重现器:

Dart 客户端与运行在 localhost 上的 WebSocket 回显服务器配合使用:

> dart run wsclient.dart --url ws://localhost:8080/websocket

2021-02-26 21:25:22.293451 Starting connection attempt to ws://localhost:8080/websocket ...
2021-02-26 21:25:22.418794 WebSocket readyState: 1
2021-02-26 21:25:23.446877 Sending 'hello'
2021-02-26 21:25:23.458083 Received data: echo of hello
2021-02-26 21:25:24.422013 Sending 'how are you?'
2021-02-26 21:25:24.422752 Received data: echo of how are you
2021-02-26 21:25:26.433450 Sending 'still there?'
2021-02-26 21:25:26.436280 Received data: echo of still there?
^C
^C

Dart 客户端无法与运行在 Google Cloud Run 上的 WebSocket 回显服务器一起工作 — Dart 客户端发送数据后 WebSocket 立即关闭

> dart run wsclient.dart --url wss://websocket-echo-server-quarkus-xxxxxxxxxx-xx.x.run.app/websocket

2021-02-26 21:25:40.539316 Starting connection attempt to wss://websocket-echo-server-quarkus-xxxxxxxxxx-xx.x.run.app/websocket ...
2021-02-26 21:25:40.844298 WebSocket readyState: 1
2021-02-26 21:25:41.851590 Sending 'hello'
2021-02-26 21:25:41.898587 CONNECTION DONE!
readyState=3
closeCode=1005
closeReason=

2021-02-26 21:25:42.847345 Sending 'how are you?'
2021-02-26 21:25:44.848959 Sending 'still there?'

你知道这是怎么发生的吗?我在代码中做错了什么吗?

非常感谢

托马斯

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)