react-native-socket-io-example icon indicating copy to clipboard operation
react-native-socket-io-example copied to clipboard

Android Issues

Open swaroopa94 opened this issue 6 years ago • 16 comments

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

swaroopa94 avatar Jul 13 '17 10:07 swaroopa94

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?

Sathyanarayan09 avatar Jul 13 '17 12:07 Sathyanarayan09

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

rhuantac avatar Oct 19 '17 17:10 rhuantac

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

Arpitrf avatar Dec 08 '17 07:12 Arpitrf

@Arpitrf Can you elaborate more?

vinnyoodles avatar Mar 09 '18 23:03 vinnyoodles

@rhuantac works for me,

xliank avatar Apr 14 '18 05:04 xliank

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 avatar Aug 03 '18 03:08 Aung-Myint-Thein

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!

Aung-Myint-Thein avatar Aug 03 '18 08:08 Aung-Myint-Thein

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.

sharathkoppolu avatar Aug 09 '18 10:08 sharathkoppolu

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

ronastlelobo avatar Oct 25 '18 10:10 ronastlelobo

Hey, Any luck anyone ?

ronastlelobo avatar Oct 31 '18 09:10 ronastlelobo

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

lorenzgrossi avatar Nov 08 '18 09:11 lorenzgrossi

Did anyone resolved the issue for android?

PriyaJainDev avatar Dec 03 '18 16:12 PriyaJainDev

bump

filipef101 avatar Dec 19 '18 18:12 filipef101

@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.

stanrud avatar Feb 23 '19 12:02 stanrud

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

ThakkarKhushbu avatar Apr 02 '19 09:04 ThakkarKhushbu

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

hrithik2322 avatar Jan 15 '20 09:01 hrithik2322