socket.io-client: Unable to connect on React-Native (only in Debug Mode)
You want to:
- 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:
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)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 19 (1 by maintainers)
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);
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.
try this on android it worked for me
<application 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
socket.io-client: 2.0.4worked for me.