2

I just set up an HTTP server (using Socket.IO 4.5.2) and managed to connect to my Flutter app (using Socket IO Client 2.0.0). This works all fine when I connect to my server via http://123.456.789.01:2345/.

Now, I want to secure the connection a bit more by making the connection via wss://123.456.789.01:2345/. Using wss 3.3.4 in my server and WebSocket Channel 2.2.0 in my Flutter app. Though, when connecting, it returns an error of type HandshakeException with the message:

Handshake error in client (OS Error: WRONG_VERSION_NUMBER(tls_record.cc:242)).

I understand the meaning of this error message (I think), I'm just too inexperienced with network exceptions to know how to approach this case.

My server code isn't anything special at the moment:

const http = require('http');

(async () => {
  const app = require('express')();
  app.use(express.json());

  const server = http.createServer(app);
  const { createServerFrom } = require('wss');
  createServerFrom(server, function connectionListener(ws) {
    /* ... */
  });

  server.listen(2345, () => {
    /* ... */
  });
})();

And my Flutter code boils down to:

import 'dart:io';
import 'package:web_socket_channel/io.dart';

final channel = WebSocket.connect("wss://123.456.789.01:2345/");
final sub = channel.asStream().listen(
  (data) {
    print("Received data! ${data}");
  },
  onError: (error) {
    print("Received error! Type: ${error.runtimeType}");
    print("Received error! ${error}");
  }
);

I didn't manage to find much about this error, so I figured to ask it here. Connecting via http://**:**/ doesn't work anymore either.

Thanks so much for your time!

M Zeinstra
  • 1,931
  • 4
  • 17
  • 46

1 Answers1

0

Since I was hosting on http (localhost), wss:// is not available. Don't be a stupid like me and just use ws:// if that works fine.

M Zeinstra
  • 1,931
  • 4
  • 17
  • 46