I try to use SocketIO in ReactNative by follow this link
https://github.com/facebook/react-native/issues/4393,
On IOS it work very well but Android it could not work
Result Of Socket Object
connected:false
index.android.js
window.navigator.userAgent = 'react-native';//'react-native';
const io = require('socket.io-client/socket.io');
export default class testApp extends Component {
componentWillMount(){
this.socket = io.connect('http://localhost:3000', {
jsonp: false,
transports: ['websocket']
});
// Socket Object connected:false
}
componentDidMount(){
console.log(this.socket);
this.socket.on('connect', () => {
console.log('ready to emit')
console.log('connected!');
});
}
// Other Code
}
package.json:
"react-native": "0.35.0",
"socket.io-client": "^1.5.1"
I could not find a similar problem. Am I missing something?
edited : I'm not sure can I test socketIO in localhost with ReactNative but It's work when I test on IOS emulator
edited2 : My fault It cannot test on local environment server but It's work on IOS not android Can Anybody Explained Why?
I also wanted to use Socket.IO with ExpressJS server and React Native but couldn't get it to work.
Then used https://facebook.github.io/react-native/docs/network.html#websocket-support with https://github.com/websockets/ws
And works great.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With