socket.io-client: Socket.Io-Client is not working on Android

@darrachequesne not working on Android… I have updated engine.io-client to 4.0.4. react-native : 0.63.4 socket.io-client:3.0.3 socket.io: 3.0.3

I have created a Hook. It’s working Good in IOS.

`import {useEffect, useRef} from ‘react’; import io from ‘socket.io-client’; import {getUniqueId} from ‘react-native-device-info’; import { MessageReq } from ‘…/Types/chat’;

const useSocket = () => { const ref = useRef<SocketIOClient.Socket>(); const sendChat = (req: MessageReq) => { ref.current!.emit(‘sendMessage’, req); };

const setUpRoom = (userGuid: string | null) => { const deviceId = getUniqueId(); const userGuid=‘xyz’; console.log(ref.current!.emit(‘online’, {deviceId, userGuid})); ref.current!.emit(‘online’, {deviceId, userGuid}); }; useEffect(() => { console.log(‘here’); const socket = io(‘http://localhost:3000’, {reconnection:true,}); ref.current = socket; }, []); return { sendChat, setUpRoom, }; }; export default useSocket;`

Log: Screenshot 2020-12-03 at 1 17 15 PM

_Originally posted by @AGurindapalli in https://github.com/socketio/socket.io-client/issues/1411#issuecomment-737726037_

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 26 (3 by maintainers)

Most upvoted comments

I got solution with just downgrade the version. I install npm install socket.io-client@2.3.0 I mean 2.3.0 version and successfully connect

@mabopoi I also face this issue but I got solution first uninstall old library first then try npm install socket.io-client@2.3.0

Thanks. It worked for me too. Following are the working versions socket.io-client@2.3.0 engine.io-client@3.4.4 ( installs along with socket.io-client) react-native@0.63.3

anyone who’s having trouble my workaround for me is this const socket = io('http://yourlocalip:3000', { transports: ['websocket'], jsonp:false, forceNew: true, });

then try restarting your server connection and restart your app

"socket.io-client": "^4.1.3"
"react-native": "0.64.2",

@mabopoi I also face this issue but I got solution first uninstall old library first then try npm install socket.io-client@2.3.0

If you are testing on a real device, I think localhost:3000 might be wrong. Is there a domain/IP address your server is exposed on? Maybe 192.168.x.x on a local subnet?

More information here: https://github.com/socketio/socket.io/tree/master/examples/react-native

Using 2.3.0 version on my app didn’t work either. It returned this error: Unable to resolve "../util" from "node_modules\engine.io-client\lib\transports\polling-xhr.js"