socket.io-client
socket.io-client copied to clipboard
Unable to connect and reconnect on react native
I was using this lib for a year and everything is going fine. I was start using RN 0.45, and 0.48 , and then 0.53.0. Everything is perfect.
Until I upgrade to react native 0.53.3, and this issue appear.
this is the error I got
{"type":"TransportError","description":{"line":"76","collumn":"7944","sourceURL":"index.android.bundle"}}
sometimes i got "timeout"
I didn't change any code, I didn't change any dependency. What I did just:
- Deleting my node_modules folder
- In package.json I change RN and react version number.
- I run 'NPM install'
I thought it might the React native issue, so I roll back to the previews version I was used 0.53.0. But this problem still exist. I roll back again to 0.48, the issue still there. and so on.
I use socket.io-client 2.0.3 (I have try 2.0.4 but not help)
- [x] report a bug
- [ ] request a feature
Setup
- OS: Windows 10 64bit
- browser: React Native
- socket.io version: 2.0.3
I have no Idea what is going on.
Hope someone will help. Thank you
+1
I resolved this by adding 'transports': ['websocket'],
option
this.socket = openSocket(socketUrl,{
'reconnection': true,
'reconnectionDelay': 500,
'reconnectionAttempts': Infinity,
'transports': ['websocket'],
});
But that option is not required, am I right? So I keep this issue open because it will break when I omitting that option.
i did have this issue after i add express to the server and added some routes
and when i added
'transports': ['websocket'],
it works fine but it disconnect after a while and
PS: it disconnect while i'm working with the app not in backround or something else.
Could you please provide a way to reproduce? (I tried with jest with no luck: https://github.com/darrachequesne/jest/commits/test/socket.io)
Setting transports to websocket also solved my problem, but of course turns off http polling which is unfortunate. Steps to reproduce:
- Install [email protected] in a react native project, add code to create a new socket io connection, and run the android emulator
- Ensure a node server is running [email protected] and enable debug logging Expected: the connection to establish (ios simulator successfully connects) Actual: socket io emits a connect_error on the client with a code of 'parse error'. Upon inspection, the xhr.response given is an empty string which socket io interprets as a parse error. The message that fails to parse seems to be the 'pong' message from the socket io server.
I have the same problem on iOS, the temporary solution of adding the option 'transports': ['websocket']
also worked for me.
Configuration:
- socket.io 2.1.1
- react 16.3.2
- react-native 0.52.0
- iOS 11.2
I am trying to connect socket.io on my react native android. however, it is not connecting. I tried some tutorials and iOS is working fine but Android is not. I have tried the 'transports':['websocket']
but still not working :( .. Any suggestions or ideas or sample codes?
My backend is Nodejs and it also used socket.io. Thanks!
I am trying to connect socket.io on my react native android. however, it is not connecting. I tried some tutorials and iOS is working fine but Android is not. I have tried the
'transports':['websocket']
but still not working :( .. Any suggestions or ideas or sample codes?My backend is Nodejs and it also used socket.io. Thanks! Did you find any solution to this i have the same problem on react-native on Android.
same issue
hello guys I have a problem on socket
it show timeout when I check on
socket.on('connect_error', (err) => { console.log('error123',err)
here is my code
for react native side
import io from 'socket.io-client'; var socket = io.connect('http://localhost:8888',{transports: ['websocket'],upgrade:false}); socket.on('news', function (data) { console.log(data); socket.emit('my other event', { my: 'data' }); });
socket.on('connect_error', (err) => {
console.log('error123',err)
});
server side:
var app = require('express')(); var server = require('http').Server(app); var io = require('socket.io')(server);
server.listen(8888); // WARNING: app.listen(80) will NOT work here!
app.get('/', function (req, res) { res.sendFile(__dirname + '/index.html'); });
io.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event', function (data) { console.log(data); }); });
index.html
I already stock need help
Even I have the issue connecting the socket-io on android. The RN is able to get connected as the client however the same for the react web app but not react mobile app. Please suggest the solution.
Try downgrading socket.io-client to 1.7.2, it works for me.
I am having issues in connecting the websocket (socket.io-client, trnasport:['websocket']) on iOS with the webserver. Interestingly, it works when I turn on "Debug JS Remotely" on the device. This might be a problem with the react-native version on iOS. Just curious if someone is facing the same issue.
For future readers:
Please check our React Native guide here: https://socket.io/how-to/use-with-react-native
Please reopen if needed.