简体   繁体   English

React-Native socket.io没有连接

[英]React-Native socket.io no connection

I wanted to use socket.io in my RN project. 我想在我的RN项目中使用socket.io。 Everything was ok, until I disabled chrome debugger. 一切正常,直到禁用Chrome调试器。 Now socket.io just doesn't work, nothing happens. 现在socket.io不能正常工作,什么也没发生。

This is not the same problem: Is it possible to combine React Native with socket.io 这不是同一个问题: 是否可以将React Native与socket.io结合使用

What's your React Native version? 您的React Native版本是什么?

In your url add ws:// like : 在您的网址中添加ws://例如:

var soc = socket('ws://192.168.1.101',{
  jsonp: false
})

It works fine on device with RN v0.21.0. 在带有RN v0.21.0的设备上运行良好。

After I upgrade RN to 0.24.0, it doesn't work again. 将RN升级到0.24.0后,它不再起作用。

I have also got this problem. 我也有这个问题。 I fixed this from this link 我通过此链接修复了此问题

You have to initialize socket like this 您必须像这样初始化套接字

this.socket = io('http://192.168.0.101', {jsonp: false, transports: ['websocket']});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM