Skip to content
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

socket.io-client not working on Android API 28 (React Native) #1351

Closed
leurs247 opened this issue Feb 27, 2020 · 8 comments
Closed

socket.io-client not working on Android API 28 (React Native) #1351

leurs247 opened this issue Feb 27, 2020 · 8 comments

Comments

@leurs247
Copy link

I want to use Socket.IO-client with React Native. My environment:

  • React Native 0.61.5
  • React 16.9.0
  • Socket.IO-client ^2.3.0

My code works on iOS, but not on Android. I'm testing on Android version 9.0 (Pie) - API 28. I do not get any errors, it just doesn't work. I'm trying to log every connection server-side (NodeJS). When I open the app in the iOS-emulator, I see a log (eg. "connection established"). When I open the same app using Android, I don't see a log.

Front-end code (simplified!): React Native

socket = io('https://127.0.0.1:8001', {
    secure: true,
    transports: ['websocket']
})
socket.on('message', () => console.log('message received'))
socket.close()

Back-end code (simplified!): NodeJS

io.on('connection', socket => {
    console.log('connection established')
    socket.on('disconnect', () => console.log('disconnected'))
})
@ashlyWeiting
Copy link

Same issue here 😥

@ryoid
Copy link

ryoid commented Mar 7, 2020

Same issue, without transports: ['websocket'] it works.

Edit: I switched to socket.io-client@2.1.1 and seems to be working.

@sfaman
Copy link

sfaman commented Mar 27, 2020

Same Issue I am facing....

@rachitgupta98
Copy link

Check out this
https://brentmarquez.com/uncategorized/how-to-get-socket-io-to-work-with-react-native/

@MatheusLima7
Copy link

Same issue here!!

@darrachequesne
Copy link
Member

Does it happen on the Android emulator, or on a real device?

On a real device, you need to be on the same network as your server (WiFi for example), and use its IP address:

const socket = io("http://192.168.0.28:3000");

@recepaltas
Copy link

Just remove http://123.456.78.0:2053 .Then change https://domain.name .

const socket = io("https://blabla.com:2053");

@darrachequesne
Copy link
Member

For future readers:

Please check our guide with React Native here: https://socket.io/how-to/use-with-react-native

Please reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants