socket.io-client icon indicating copy to clipboard operation
socket.io-client copied to clipboard

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

Open leurs247 opened this issue 5 years ago • 6 comments

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'))
})

leurs247 avatar Feb 27 '20 20:02 leurs247

Same issue here 😥

ashlyWeiting avatar Mar 02 '20 08:03 ashlyWeiting

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

Edit: I switched to [email protected] and seems to be working.

ryoid avatar Mar 07 '20 06:03 ryoid

Same Issue I am facing....

sfaman avatar Mar 27 '20 10:03 sfaman

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

rachitgupta98 avatar Jul 19 '20 12:07 rachitgupta98

Same issue here!!

MatheusLima7 avatar Feb 03 '24 22:02 MatheusLima7

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");

darrachequesne avatar Feb 05 '24 11:02 darrachequesne

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

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

recepaltas avatar Feb 27 '24 12:02 recepaltas

For future readers:

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

Please reopen if needed.

darrachequesne avatar Apr 08 '24 16:04 darrachequesne