SocketCluster / socketcluster-client

JavaScript client for SocketCluster
MIT License
291 stars 92 forks source link

v5.0.17 'socket hangup' error for React Native iOS Only, works for Browser and Andriod #68

Closed bikashsharmabks closed 7 years ago

bikashsharmabks commented 7 years ago

Facing issue with v5.0.17 with socket hang up error for React Native iOS app only, whereas it works perfectly fine with Browser and React Native Android app.

Here is error log from Browser: screen shot 2016-11-03 at 4 47 23 pm

Note: plist already has

    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
jondubois commented 7 years ago

@bikashsharmabks What options do you pass to socketCluster.connect(...)? Did does it work with v5.0.14?

I tested it v5.0.17 on RN iOS yesterday and it worked for me - So maybe it's related to settings.

jondubois commented 7 years ago

@bikashsharmabks Also, what version of socketcluster and socketcluster-server are you using on the server side?

bikashsharmabks commented 7 years ago

@jondubois

Version Details: socketcluster": 5.0.18

Here is the code which I have

var options = {
      hostname: 'dev.sandbox.com',
      path: '/mySocketEventCluster',
      port: 80,
    }
    this.socket = socketCluster.connect(options);

    this.socket.on('connect', function (err) {
        console.log('CONNECTED');
        //Alert.alert('hi','connected');
    });

    this.socket.on('error', function (err) {
        console.log(err);
        //Alert.alert('err', err.message);
    });

Note this works in browser, RN Android but not in RN iOS

jondubois commented 7 years ago

@bikashsharmabks Maybe try to setup a very simple app (from scratch) with only basic SC logic to connect and emit/publish events and let me know if it works. We need to rule out the possibility that this is caused by some other code which is interfering with SC like middleware...

Yesterday I did a very simple test with socketcluster-client v5.0.17 and it was connecting, publishing and receiving messages with socketcluster v5.0.18 on the server side - It was running on iOS simulator on Mac.

bikashsharmabks commented 7 years ago

@jondubois It worked I took a sample code from socketcluster getting started and it worked for RN iOS!!!

But still wondering what is issue with my configuration as it works with Android and browser and not with iOS

bikashsharmabks commented 7 years ago

@jondubois I got the issue I was setting wsEngine to 'ws' which is not workging for iOS and when I change it to 'uws' it worked!!!

so is there any issue with 'ws'?

jondubois commented 7 years ago

Interesting, on RN iOS on the client side, it will use the native WebSocket object provided by RN which in theory should be compatible with both ws and uws on the server, but maybe this is not the case, I'll have to check.

bikashsharmabks commented 7 years ago

@jondubois thanks a lot for your help.

Please go ahead and close this issue or otherwise if you want to track the wsengine issue with this one

yogi9999999 commented 7 years ago

@bikashsharmabks it would be really help full if you tell me how you configured the socket cluster client in react native android.

AustinHunt commented 7 years ago

This does not work in react-native iOS for protocol:HTTPS port:443 server. Trying secure ws connections hasn't worked for me, but it works using localhost. Please advise.

jondubois commented 7 years ago

@NomadGraphix There is no protocol option, there is a secure (boolean) option though. See the list of supported options here: http://socketcluster.io/#!/docs/api-socketcluster-client

AustinHunt commented 7 years ago

@jondubois Well, that is quite interesting. 👍

@yogi9999999, @bikashsharmabks The documentation looks to be lacking on github: https://github.com/SocketCluster/socketcluster-client

This is what I was using, but it is out of date.

var options = {
    protocol: 'https',
    hostname: 'example.com',
    port: 443
};

// Initiate the connection to the server
var socket = socketCluster.connect(options);