我正在我的 flutter 应用程序中实现 web socket,我正在使用 stomp_dart_client 版本:0.4.1, 这是我的服务:
Future<StompClient> connect() async{
String url ='wss://$baseUrl:$portApiGatway/socket';
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
String token = sharedPreferences.getString('token');
StompClient client = StompClient(
config: StompConfig(
reconnectDelay: new Duration(seconds: 1),
url: url,
onConnect: (c){
print("Connected");
},
beforeConnect: () async {
print('waiting to connect...');
await Future.delayed(Duration(milliseconds: 200));
print('connecting...');
},
onWebSocketError: (dynamic error) => print(error.toString()),
stompConnectHeaders: {'Authorization': 'Bearer $token'},
webSocketConnectHeaders: {'Authorization': 'Bearer $token'},
));
client.activate();
print(client.connected);
return client;}
当我尝试使用 http 时,抛出了 unsuproted 协议的错误,这就是我将协议更改为 wss 的原因 和这里的实现:
getClient() async{
WebSocketService webSocketService = WebSocketService();
client = await webSocketService.connect();}
@override
void initState() {
// TODO: implement initState
super.initState();
getClient();
print(client.connected);
}
但我收到此错误: I/flutter (5796):HandshakeException:客户端中的握手错误(操作系统错误: I/flutter (5796): WRONG_VERSION_NUMBER(tls_record.cc:242))
有什么帮助吗??