socket.io-client-dart icon indicating copy to clipboard operation
socket.io-client-dart copied to clipboard

Port number 0 is added to url automatically

Open reshamRudra opened this issue 3 years ago • 6 comments

Why it is adding port number zero at the end of url automatically ? How can i remove the port number. I want to run it without port number.

reshamRudra avatar Aug 31 '21 04:08 reshamRudra

same problem

HHongois avatar Oct 29 '21 13:10 HHongois

@jumperchen can you please have a look at it? Here are the details.

  • client : ^2.0.0-beta.4-nullsafety.0
  • platform : flutter web
  • server : version 3.1.2

Here is the code.

import 'package:socket_io_client/socket_io_client.dart' as IO;

IO.Socket socket = IO.io(
      'wss://socket.example.com',
      IO.OptionBuilder()
          .setTransports(['websocket'])
          .build());

With the above code, the URL becomes: wss://socket.example.com:0/socket.io/?EIO=4&transport=websocket :0 after socket.example.com

I think the issue is with the file socket_io_client.dart:49. If no port is passed then due to null safety it takes default int value 0.

Solution:

For those who are looking solution for it, pass a port number while connecting. If no custom port by server, for ws pass 80 for wss pass 443. Example:

import 'package:socket_io_client/socket_io_client.dart' as IO;

IO.Socket socket = IO.io(
      'wss://socket.example.com:443',
      IO.OptionBuilder()
          .setTransports(['websocket'])
          .build());

neeraj-htp avatar Dec 13 '21 14:12 neeraj-htp

Same issue

vukhacbiet avatar May 11 '22 13:05 vukhacbiet

@neeraj-htp thanks for the support. Some of are connecting to services that cannot expose port numbers unfortunately. This is a quick fix via a PR.

ollyde avatar May 22 '22 22:05 ollyde

@neeraj-htp This doesn't seem to solve the issue. Having the same issue on android device, even after mentioning the port number in the url.

rahul-sinha1908 avatar Jun 08 '22 17:06 rahul-sinha1908

Any one get the solution?

Hassan6197 avatar Oct 05 '22 19:10 Hassan6197

@Hassan6197 you had to set the port number, usually providers like Google Cloud use 443 as the default for this type of traffic.

ollyde avatar Oct 06 '22 09:10 ollyde