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

Unable to connect on React-Native (only in Debug Mode) #1259

Closed
1 of 2 tasks
jr-k opened this issue Jan 3, 2019 · 19 comments
Closed
1 of 2 tasks

Unable to connect on React-Native (only in Debug Mode) #1259

jr-k opened this issue Jan 3, 2019 · 19 comments

Comments

@jr-k
Copy link

jr-k commented Jan 3, 2019

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)
@jr-k
Copy link
Author

jr-k commented Jan 3, 2019

oops duplicate of #1245

@jr-k jr-k closed this as completed Jan 3, 2019
@jr-k
Copy link
Author

jr-k commented Jan 3, 2019

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.

@jr-k jr-k reopened this Jan 3, 2019
@EliasTouil
Copy link

EliasTouil commented Jan 14, 2019

I'm facing the same issue

@jr-k 's issue persists after @anooj1483 's hack according to #1245 (comment) in #1245
It is the same for me

@mostafiz93
Copy link

mostafiz93 commented Feb 18, 2019

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"

@Reardonp
Copy link

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"

@mostafiz93
Copy link

socket.io-client: 2.0.4 worked for me.

@ningacoding
Copy link

ningacoding commented Feb 28, 2019

I'm getting error on ussing 2.0.4 + ReactNative

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

image

@ningacoding
Copy link

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);

@reza-madani
Copy link

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

@jaredstevick
Copy link

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

@ningacoding
Copy link

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

@diegolaciar
Copy link

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

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

Cheers

@autotrof
Copy link

autotrof commented Sep 3, 2019

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 👍 👍

@Ramesh21071993
Copy link

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?

@karriz-dev
Copy link

karriz-dev commented Mar 10, 2020

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 :(

@karriz-dev
Copy link

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

@berto6544
Copy link

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

@dtembo98
Copy link

dtembo98 commented Apr 27, 2023

"react-native": "0.70.5",
"socket.io-client": "^4.6.1",

This how i setup my socket connection as per the docs

import { io } from "socket.io-client"

const URL = "http://localhost:3030"
const socket = io(URL, { autoConnect: false })
socket.onAny((event, ...args) => {
  console.log("All event listener...", event, args)
})
export default socket

Only working in debug mode

@darrachequesne
Copy link
Member

For future readers:

Please check our guide with React Native here: https://socket.io/how-to/use-with-react-native

Please reopen if needed.

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

15 participants