R
R
Roman Alexandrovich2019-02-21 14:30:03
React Native
Roman Alexandrovich, 2019-02-21 14:30:03

How to connect to a socket?

Hello.
I'm trying to connect to a socket using socket.io-client but I only get SocketRocket: In debug mode in the console. Allowing connection to any root cert. I checked different versions of the library and react-native and nothing works. I thought that the server address was not correct, but I checked it and it works as it should. I also created node js on localhost, turned to it and everything works, but it does not connect to a remote server.
"socket.io-client": "2.0.4",
"react-native": "0.58.3",

import SocketIOClient from 'socket.io-client';

componentDidMount() {

        this.socket = SocketIOClient('wss://bitshares.openledger.info/ws',{
          'force new connection': true,
            reconnection: true,
            reconnectionDelay: 10000,
            reconnectionDelayMax: 60000,
            reconnectionAttempts: 'Infinity',
            timeout: 10000,
            transports: ['websocket']
        });
        this.socket.connect();
        // this.socket.send('123');
        this.socket.on('connect', () => {
            console.log("CONNECTED")
        });
        this.socket.onopen=function(){
            console.log("onopen")
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
polarlord, 2019-02-21
@RomReed

Have you tried doing the same but without socket.io ? Like here . On the code from the example on your link, connect happens without problems. Checked on expo, not cli.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question