Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

socket-io.clent does not work under React Native Android app

I use socket-io.client library in ReactNative app. It works great on iOS but crashes android application.

Error in packager:

Directory ..node_modules\engine.io-client\lib\transports\index.j\lib\xmlhttprequest.js doesn't exist

react-native-cli: 2.0.1 react-native: 0.40.0

I trying react-native 0.39 and get same error.

like image 696
olegdev Avatar asked Nov 30 '25 07:11

olegdev


1 Answers

I was having the same issue, it is caused by how the library is imported.

var io = require("socket.io-client/dist/socket.io");

In your constructor

constructor(props) {
    super(props);
    this.socket = io('http://10.0.2.2:3000', { jsonp: false });
}

If you are using an Android emulator, use 10.0.2.2 to connect to a node server running locally on your development machine.

like image 100
gamedevranjit Avatar answered Dec 03 '25 09:12

gamedevranjit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!