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

Android Issues #7

Open
swaroopa94 opened this issue Jul 13, 2017 · 16 comments
Open

Android Issues #7

swaroopa94 opened this issue Jul 13, 2017 · 16 comments

Comments

@swaroopa94
Copy link

Hi,

This example is working fine in iOS but in android it is not at all working .

How Can I solve this?
Please help me in solving this

@Sathyanarayan09
Copy link

Its not working on Android and Im getting an error as -- Unknown named module: 'xmlhttprequest-ssl' --
can you please help me to fix this issue?

@rhuantac
Copy link

If anyone having this issue yet, I've found a simple fix here: https://stackoverflow.com/a/41400394

Just change line 3 of client\index.js to:

import SocketIOClient from 'socket.io-client/dist/socket.io.js';

@Arpitrf
Copy link

Arpitrf commented Dec 8, 2017

The same problem. Not working in android, but working in ios.
Also tried @rhuantac solution. Still dosen't work.

@vinnyoodles
Copy link
Owner

@Arpitrf Can you elaborate more?

@xliank
Copy link

xliank commented Apr 14, 2018

@rhuantac works for me,

@Aung-Myint-Thein
Copy link

Aung-Myint-Thein commented Aug 3, 2018

I just tried the repo. It is working fine on iOS but on Android, I am not receiving anything. I cannot debug remotely too.

I tried adding these lines in the constructor but nothing come out too.

this.socket.on('disconnect', () => {
      alert('disconnected');
    });

    this.socket.on('connect', () => {
      alert('connected');
    })

Can you please try the repo on Android and see if it is working? or do you have any idea where it could be wrong in our settings? Thanks!

@Aung-Myint-Thein
Copy link

Aung-Myint-Thein commented Aug 3, 2018

I managed to work for Android too. For android, we cannot use 127.0.0.1 or localhost. Need to specify the server machine's IP address. Thanks! :D sorry for wrong flag!

@sharathkoppolu
Copy link

This example is working fine but when I tried to use the client code in another project I am receiving this warning:
Received data was not a string, or was not a recognized encoding.

React Native Environment Info:
System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
Memory: 1.56 GB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.9.1 - /usr/local/bin/node
npm: 5.5.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
IDEs:
Android Studio: 3.0 AI-171.4408382
Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
npmPackages:
react: 16.4.1 => 16.4.1
react-native: 0.56.0 => 0.56.0
npmGlobalPackages:
react-native-cli: 2.0.1

Package.json file:
{
"name": "xyz",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"axios": "^0.18.0",
"react": "16.4.1",
"react-native": "0.56.0",
"react-native-gifted-chat": "^0.4.3",
"react-native-image-picker": "^0.26.10",
"react-navigation": "^2.9.3",
"socket.io": "^2.1.1",
"underscore": "^1.9.1"
},
"devDependencies": {
"babel-jest": "23.4.2",
"babel-preset-react-native": "5.0.2",
"jest": "23.4.2",
"react-test-renderer": "16.4.1"
},
"jest": {
"preset": "react-native"
}
}

I am not able to debug the code also. please help me.

@ronastlelobo
Copy link

@Aung-Myint-Thein so how did you do it. Please share code snippets or example.

@ronastlelobo
Copy link

Hey, Any luck anyone ?

@lorenzgrossi
Copy link

lorenzgrossi commented Nov 8, 2018

Hi, this example still not work on Android phone!

I tried on 2 physical devices:

  • Nexus 5 (Android 6.0.1)
  • Nexus 5X (Android 8.0.1)

This is what I got in my package.json:
{
"name": "react-native-socket-io-example",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"ios": "react-native run-ios",
"android": "react-native run-android",
"server": "nodemon server"
},
"dependencies": {
"express": "^4.14.0",
"mongojs": "^2.4.0",
"nodemon": "^1.11.0",
"react": "15.4.1",
"react-native": "0.39.2",
"react-native-cli": "^2.0.1",
"react-native-gifted-chat": "0.0.10",
"socket.io": "^1.7.2"
},
"devDependencies": {
"babel-jest": "18.0.0",
"babel-preset-react-native": "1.9.1",
"jest": "18.0.0",
"react-test-renderer": "15.4.1"
},
"jest": {
"preset": "react-native"
}
}

When I run the npm run android command the application starts correctly on the device, but when I try to send message I receive this error:
com.reactnativesocketioexample E/ReactNativeJS: In this environment the sources for assign MUST be an object.This error is a performance optimization and not spec compliant.

I added a listener on the 'connect_error' event in client/index.js file :
this.socket.on('connect_error', (err) => { console.log('socket connected error --> ' + err); })

after some minutes since the start of the application I see the log:
socket connected error --> timeout

Any suggestions ?

Thanks

@PriyaJainDev
Copy link

Did anyone resolved the issue for android?

@filipef101
Copy link

bump

@stanrud
Copy link

stanrud commented Feb 23, 2019

@priya0607jain @ronastlelobo @filipef101
The easy and fast solution is:
Put your local IP address instead of 127.0.0.1 or localhost.

If you don't know how to check your IP
Run the command in the terminal to find out:
Use ipconfig getifaddr en1 for wireless, or ipconfig getifaddr en0 for ethernet.

@ThakkarKhushbu
Copy link

Still not working for Android. can someone suggest something which can work on both platform?

@hrithik2322
Copy link

Did anyone find the android fix not able to connect to server from client

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