Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not upgraded to websocket #380

Open
VishalKumarMauray opened this issue Sep 9, 2024 · 3 comments
Open

not upgraded to websocket #380

VishalKumarMauray opened this issue Sep 9, 2024 · 3 comments

Comments

@VishalKumarMauray
Copy link

Unhandled Exception: WebSocketException: Connection to 'https://testing.lm25aarogyaindia.com:0/ws#' was not upgraded to websocket

  • using java as backend

java code:-
@configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
    config.enableSimpleBroker("/notifications");
    config.setApplicationDestinationPrefixes("/app");
}

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/ws");
    registry.addEndpoint("/ws").withSockJS();
}

}

flutter code:-
import 'package:flutter/material.dart';
import 'package:web_socket_channel/web_socket_channel.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
const MyApp({super.key});

@OverRide
Widget build(BuildContext context) {
const title = 'WebSocket Demo';
return const MaterialApp(
title: title,
home: MyHomePage(
title: title,
),
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({
super.key,
required this.title,
});

final String title;

@OverRide
State createState() => _MyHomePageState();
}

class _MyHomePageState extends State {
final TextEditingController _controller = TextEditingController();
final _channel = WebSocketChannel.connect(
Uri.parse('wss://echo.websocket.events'),
);

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Form(
child: TextFormField(
controller: _controller,
decoration: const InputDecoration(labelText: 'Send a message'),
),
),
const SizedBox(height: 24),
StreamBuilder(
stream: _channel.stream,
builder: (context, snapshot) {
return Text(snapshot.hasData ? '${snapshot.data}' : '');
},
)
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _sendMessage,
tooltip: 'Send message',
child: const Icon(Icons.send),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}

void _sendMessage() {
if (_controller.text.isNotEmpty) {
_channel.sink.add(_controller.text);
}
}

@OverRide
void dispose() {
_channel.sink.close();
_controller.dispose();
super.dispose();
}
}

it is connecting to echo server without any error but when i change the url to the desired one it shows the error

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: WebSocketException: Connection to 'https://testing.lm25aarogyaindia.com:0/ws#' was not upgraded to websocket

@VishalKumarMauray
Copy link
Author

web_socket_channel: ^2.4.0

i am using this version of the package

@Mae623
Copy link

Mae623 commented Sep 14, 2024

I meet this question, too. Then I find there is a bug in my server. Hoping my experience will help you.

@VishalKumarMauray
Copy link
Author

which type of bug you find in your server will you please guide for my project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants