-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
version 2.2 does not work with react native #1254
Comments
experienced the same issue on both platform (simulator) 2.1.1, it only works with turning debugger on. |
I am also facing this issue. I upgraded to see if it fixes my first connect latency issue. |
I am also facing the same. issue Reverting to 2.1.1 works for me. |
I am still facing same issue reverting 2.1.1 also not working for me. |
It should be fixed by socketio/engine.io-client#607. @benhjames could you confirm your fix has fixed the issue in React Native? |
Yep, I'm currently running It's worth checking to make sure your |
@benhjames @darrachequesne I have used socket.io-client@2.2.0 (which has pulled in engine.io-client@3.3.2) and also verify the changes in node_modules still, it's not working for me. `import io from 'socket.io-client'; export default class HomeScreen extends React.Component { I am getting the error as below : |
That looks to me like the endpoint is incorrect - it should be a |
@benhjames I earlier tried with WebSocket API https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API and it was working perfectly fine with the same protocol. |
socket.io (unlike the WebSocket API) only accepts a HTTP(S) protocol URI for the client (see the docs here), but it does use the WS protocol behind the scenes. So if you do |
@benhjames thanks for the update! I think the this.socket = io('ws://192.168.0.107:8080', {
path: '/endpoint',
reconnection: true,
reconnectionDelay: 500,
jsonp: false,
reconnectionAttempts: Infinity,
transports: ['websocket']
}); |
@darrachequesne I have tried above implementation but it's still not working. |
Perhaps it might be useful seeing what the SocketIO server code looks like, just to make sure it's using the right namespace and settings etc. 🙂 |
It's working perfectly fine with WebSocket API but when I try to connect with Socket.io API I am getting an error as below:
|
If it works with the WebSocket API with no custom logic to unserialise socket.io payloads, then that implies that the server isn't using socket.io. Is there any chance you could provide some code from the server to verify if this is the case? |
@benhjames That's right we are using https://docs.oracle.com/javaee/7/api/javax/websocket/package-summary.html for backend code. |
That explains it then! Socket.io needs to be used on both the client and server to work. 👍 |
@benhjames @darrachequesne Now I am using socket.io in the backend, it's working fine on the frontend with vanilla javascript using socket.io but when I try to connect socket.io through React Native I am getting the error: Vanilla JS(Working Perfectly fine) :
React Native code: (Not working)
Error:
I am using https://github.com/mrniko/netty-socketio in backend. |
It may be needed to connect to a non-localhost URL (i.e. your computer's IP) within React Native: certainly in Android and possibly in iOS depending on which simulator is being used. If that still doesn't work, then it's worth trying the |
@benhjames I am facing a strange issue. I am using https://github.com/mrniko/netty-socketio in the backend and if I am using Vanilla JS as above mentioned it's working perfectly fine but if I am using with react-native, server showing a successful connection but in react-native, I am getting connection-error as below :
PS: |
Please see the above answer! |
Thanks, @benhjames for your support, It's working now. mrniko/netty-socketio#614 |
I have the same problem no matter if I chose websockets or polling. Its either a websocket_error or a xhr poll error. The URL is an IP (http://192.168.1.112:3000) and I am connecting from a physical phone to a computer on the same local network using React Native Expo. I can help out if you need more stack traces or info... socket.io 2.2.0 // both client and server |
Sounds like a problem outside of socket.io, if both the websocket and polling transport aren't working. You may want to try:
|
Gonna try the first test, the normal fetch works EDIT: it looks like a CORS related problem. If I try to connect a simple JS client I get:
Any advice on how to setup this? |
try last version from github, like this, solved my issues with RN android:
|
Nothing seems like to be working with react native 0.60 |
Android release build is not working when using RN 0.60.5 Tried socket.io-client versions 2.0.4, 2.1.1, 2.2.0. Tried |
See #1305 - on Android you need to use https or set the usesCleartextTraffic attribute in AndroidManifest |
try v2.3 |
I tried with Expo SDK v34 and v35 (RN 0.59) and had to downgrade socket.io-client to 1.7.2 ( |
Hi @lionbur , as I know there are many mini version of 0.59. Which version are you using? 0.59.9? Thank you in advance! |
For future readers, please check the code example here: https://github.com/socketio/socket.io/tree/master/examples/react-native |
You saved my head from headache! |
Reverting to 2.1.1 fixes the problem.
I suspect it has something to do with the new cors management changes.
Manually Setting origins does not seem to do anything.
It magically start working when launching the react native debugger.
Config
Setup
The text was updated successfully, but these errors were encountered: