Socket.io-client: Unable to connect on React-Native (only in Debug Mode)

Created on 3 Jan 2019  ·  19Comments  ·  Source: socketio/socket.io-client

### You want to:

  • [x] report a _bug_
  • [ ] request a _feature_

### Current behaviour
I can't connect via socket io to my server, it times out.

### Steps to reproduce (if the current behaviour is a bug)
In react-native:

```js
import io from 'socket.io-client';

const BACKEND = 'my socketio server url'

const sock = io(BACKEND, { transports: ['websocket'], forceNew: true });
sock.on('connected', () = {
debugger;
})
```

The debug logs look like:

There is nothing only a timeout triggered

### Expected behaviour
I expect to be able to connect to my socketio server, the same way I am able to in a web browser.

### Setup

  • OS: Android 8.0
  • browser: React-native
  • socket.io version: 2.1.1 (but tried differents verisons with same result)

Most helpful comment

Facing the same issue. Works well when debug mode is on, but doesn't work when Debug mode is turned off or apk is built with release mode.

Versions:
"react": "16.8.2",
"react-native": "0.58.4",
"socket.io-client": "^2.2.0"

All 19 comments

I'm reopening this issue, this is slightly different.

I tried to install socket io on a fresh react-native installation 0.57.8 and I'm facing this issue again.

Facing same issue. Not working in RN version 0.57.3. Works fine when connects to local server. But it is not connecting to the main backend server.

React Native: 0.57.8
React: 16.6.3
socket.io-client: 2.0.4

This worked for me. Also need to change the socketio js version in server side to 2.0.4

I'm facing the same issue

@jr-k 's issue persists after @anooj1483 's hack according to https://github.com/socketio/socket.io-client/issues/1245#issuecomment-451285245 in #1245
It is the same for me

Facing the same issue. Works well when debug mode is on, but doesn't work when Debug mode is turned off or apk is built with release mode.

Versions:
"react": "16.8.2",
"react-native": "0.58.4",
"socket.io-client": "^2.2.0"

Same issue as everyone else. Works perfectly if debugging.
React Native App versions:
"react": "16.5.0",
"react-native": "^0.58.4",
"socket.io-client": "^2.1.1"

Server Version:
"socket.io": "2.0.4"

socket.io-client: 2.0.4 worked for me.

I'm getting error on ussing 2.0.4 + ReactNative

TypeError: undefined is not an object (evaluating 'n.protocol')

image

FIXED IT for me when i was adding host:port like next in debug mode:

const socket = io("//domain.com:port", opts); // this works only in debug mode

didn't worked in NO debug mode, i had to add the protocol:

const socket = io("http://domain.com:port", opts);

I have the same issue
react-native : 0.57.8,
socket-io-client : 2.2.0
only works when debug is enabled

has anyone found a fix for this yet? i have tried several different versions of the package with no luck

there are many causes of this error/bug, mine was only one of many.

try last version from github, like this, solved my issues with RN android:

npm i socketio/engine.io-client#3.3.2 -S

Cheers

FIXED IT for me when i was adding host:port like next in debug mode:

const socket = io("//domain.com:port", opts); // this works only in debug mode

didn't worked in NO debug mode, i had to add the protocol:

const socket = io("http://domain.com:port", opts);

its works on socket.io 2.1.1 and react-native 0.59.8. love you @ningacoding 👍 👍

Hi @autotrof,
I tried with react-native 0.59.8 and socket.io, but it can't connect in release build.
Am using ip and port to connect,
Can you please help me?

Anyone cannot solved yet?
In my case

react-native : 0.61.5
socket.io-client: 2.3.0 (I tried another version, 2.1.1, 2.0.1, 2.1.0)

I likewise only in debug mode worked :(

I solved this problem change console.dir() to console.log()
console.dir() function is not support to release mode 😃😃

try this on android it worked for me

android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:usesCleartextTraffic="true" <-- add this

Was this page helpful?
0 / 5 - 0 ratings