【发布时间】:2017-03-07 16:49:00
【问题描述】:
我尝试通过点击此链接在 ReactNative 中使用 SocketIO
https://github.com/facebook/react-native/issues/4393,
在 IOS 上运行良好,但在 Android 上无法运行
套接字对象的结果
已连接:假
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!');
});
}
package.json
"react-native": "0.35.0",
"socket.io-client": "^1.5.1"
我找不到类似的问题 我错过了什么?
编辑: 我不确定是否可以使用 ReactNative 在 localhost 中测试 socketIO,但是当我在 IOS 模拟器上测试时它可以工作
已编辑2: 我的错它无法在本地环境服务器上测试 但它适用于 IOS 而不是 android 谁能解释一下为什么?
【问题讨论】:
标签: socket.io react-native react-native-android