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

{name: "SocketProtocolError", message: "Socket hung up", code: 1006} #48

Open
mingkang1993 opened this issue Oct 12, 2016 · 27 comments
Open

Comments

@mingkang1993
Copy link

e18fdff9-d084-45aa-bef3-4e2826840bdd

@zalmoxisus
Copy link
Owner

Thanks for the report. Could you please check what version of sc-broker-cluster do you have installed? It seems related to SocketCluster/sc-broker-cluster@ea5e7ba, though I don't see stringify function in use.

\cc @jondubois

@jondubois
Copy link

@zalmoxisus @mingkang1993 the dependency sc-broker-cluster should be v2.1.6 or later. Maybe an earlier version was cached by npm from an earlier install? @mingkang1993 Try reinstalling/updating the dependency after doing npm cache clean.

@devken-net
Copy link

i've got a same error:

{
code:1006
message:"Socket hung up"
name:"SocketProtocolError"
...
}

my sc-broker-cluster is v2.1.7

@jondubois
Copy link

jondubois commented Nov 11, 2016

@Markortiz Do you also get "...stringify is not a function" on the server side?
Are you running it over the network; if so, are you using plain HTTP/WS (not encrypted)?

Some corporate networks can block plain WebSocket traffic; the solution is to serve it over HTTPS.

Another thing that you can try is check that you're using the latest versions of https://www.npmjs.com/package/socketcluster and https://www.npmjs.com/package/socketcluster-server

Annother thing to check are your settings to make sure that it's connecting to the correct server URL.
This error just means that the server was lost or could not be found (including blocked by a proxy).

@devken-net
Copy link

@jondubois I'm just trying to run my react-native on local, here attached error screenshot:
desctop screenshot

Its still appear after updating socketcluster

@jondubois
Copy link

@Markortiz Did you run npm cache clean and then reinstall remote-redux-devtools (and socketcluster)?
I cannot reproduce this - Maybe there is an old subdependency that is cached and not updating correctly.

@devken-net
Copy link

@jondubois I fix it by deleting node_modules and run npm install again and that error was gone.
However it seems that I can't see any state nor actions on my Redux Devtools extension on chrome which I think a separate issue.

Thanks for the help! :)

@zalmoxisus
Copy link
Owner

zalmoxisus commented Nov 14, 2016

@Markortiz did you open Remote DevTools?
redux_devtools

In case you're running a local server (which is recommended), don't forget to specify the host and port for the extension by clicking the Settings button there.

@devken-net
Copy link

devken-net commented Nov 14, 2016

@zalmoxisus yes, I'm using "remotedev-server": "^0.2.0" and run remotedev --hostname=localhost --port=8000 --injectserver=reactnative then run react-native run-android

and I cant see any activities on Redux Devtools

desctop screenshot2

@zalmoxisus
Copy link
Owner

Did you specified host and port on both the extension and remote-redux-devtools (and don't forget about realtime parameter)?

  import { createStore, applyMiddleware } from 'redux';
  import { composeWithDevTools } from 'remote-redux-devtools';

  const composeEnhancers = composeWithDevTools({ realtime: true, port: 8000 });
  const store = createStore(reducer, /* preloadedState, */ composeEnhancers(
    applyMiddleware(...middleware),
    // other store enhancers if any
  ));

Just in case also run adb reverse (though it shouldn't be necessary when having injectserver=reactnative).

@devken-net
Copy link

@zalmoxisus thanks for your help! adb reverse was able to solve the problem. :)

@jakecraige
Copy link

I also ran into this when attempting to connect on an iOS device, and it was caused by a mismatch between the dev server's configuration and the store enhancer. I had:

devTools({hostname: '10.0.0.4', port: 8000})

and

$ remotedev-debugger --hostname=localhost --port=8000 --injectserver=reactnative

Once I made the hostname of the shell command match, all worked :)

@darth-cheney
Copy link

I am experiencing the same WS error (1006, Connection Refused) when attempting to load the tools via a Django-hosted application:

WebSocket connection to 'ws://localhost:8181/socketcluster/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

The relevant lines in my store look like this:

import {composeWithDevTools} from 'remote-redux-devtools';
/* ... */
// DevTools setup
const composeEnhancers = composeWithDevTools({realtime: true, port: 8181});

const store = createStore(
    rootReducer,
    initState,
    composeEnhancers(applyMiddleware(thunk))
);

Per the above posts, I am using sc-broker-cluster v4.0.0.

None of this works even if I set the tools to use local hosting on any port or even when I attempt to match hostnames between the web server and the devtools.

@zalmoxisus
Copy link
Owner

zalmoxisus commented Jan 3, 2017

@darth-cheney, make sure your server is available on http://localhost:8181.

@darth-cheney
Copy link

I am using atom-redux-devtools and have attempted to match the hostname/port settings as in the store, but no dice. My understanding was that atom-redux-devtools took care of the server part -- is that not the case? Either way I cannot get this to work eve with the plain remotedev.io.

I'm wondering now if this is at all even possible, since my webserver is Django and I cannot simply import a remotedev-server to start myself

@zalmoxisus
Copy link
Owner

zalmoxisus commented Jan 3, 2017

@darth-cheney, if you don't use remotedev.io (which is by default), you should install and start remotedev-server:

npm i -g remotedev-server && remotedev --port=8181

or if you don't want to install it globally:

npm i --save-dev remotedev-server && ./node_modules/bin/remotedev --port=8181

It's not trivial to integrate it in an atom package, see zalmoxisus/atom-redux-devtools#1.

@darth-cheney
Copy link

Ok I'll try to keep this as the last post, since it's veered off topic.

Initially, I tried the default (remotedev.io) and my store looked like this:

import {composeWithDevTools} from 'remote-redux-devtools';
/* ... */
const store = createStore(
    rootReducer,
    initState,
    composeWithDevTools(applyMiddleware(thunk))
);

Additionally, I had NODE_ENV set to development (even though this isn't a node server).

However, nothing worked in either atom-redux-devtools or the remotedev.io development tools. Everything stayed blank and there were no warnings anywhere. I'd prefer not to run a custom server if I don't have to, but went down that road when nothing was happening. Any other ideas?

@zalmoxisus
Copy link
Owner

zalmoxisus commented Jan 3, 2017

Make sure to set process.env.NODE_ENV. For Webpack you should add it as following:

plugins: [
  new webpack.DefinePlugin({
    'process.env.NODE_ENV': JSON.stringify('development')
  })
]

You can just set realtime to true or to other global variable to turn it off in production. If you don't specify port parameter, it will use remotedev.io. Also make sure not to switch to a local server in Settings of the monitor app (either in Atom or on remotedev.io/local).

You might also want to try our examples.

If you're using it for React Native, there's React Native Debugger, which already includes both the server and remote-redux-devtools.

Feel free to provide more info, I'd happy to help.

@darth-cheney
Copy link

Yup, I'm an idiot. Needed to set NODE_ENV on the build for the JS bundle!

Thanks @zalmoxisus, this is working now. Much appreciated.

zalmoxisus added a commit that referenced this issue Jan 3, 2017
@zalmoxisus
Copy link
Owner

@darth-cheney no probs. I added the info to the README.

@SSTPIERRE2
Copy link

SSTPIERRE2 commented Dec 4, 2017

@zalmoxisus Man I've been at this for hours and cannot get this package to work with react-native run-android. As soon as I added remotedev-debugger --hostname=localhost --port=8000 --injectserver=reactnative as a postinstall script in my RN-redux app it cannot build.

I get the error described above while building my app or even using the remotedev packages' remotedev --hostname=localhost --port=8000 command directly. It says something about installing C++ compiler, do I need that? No docs say I need this. I've done the adb reverse thing and it does not help.

The error comes from socketcluster-server\scserver.js.

@jondubois
Copy link

jondubois commented Dec 4, 2017

@SSTPIERRE2 Which version of Node.js are you using?
I think that this could be a combination of two issues:

  1. Your machine doesn't have the required C++ compiler (version) to build the uws module as part of the regular installation process. Installing or upgrading your C++ compiler version should fix the issue.
  2. The version of socketcluster-client (^5.3.1) that is used doesn't have the pre-built binaries for uws for that specific Node.js version - New versions of socketcluster-client have the latest uws binaries so bumping up the socketcluster-client dependency should fix the issue.

@SSTPIERRE2
Copy link

SSTPIERRE2 commented Dec 5, 2017

@jondubois Thanks for the quick reply!

I'm running Node 9.2, Windows 8.1, have Visual C++ 2015, just installed GCC, socketcluster-client ^9.0.0, and uws to no avail. I can't even use the remotedev command by itself, I just get get the C++ compile error.

@jondubois
Copy link

jondubois commented Dec 5, 2017

@SSTPIERRE2 It's likely related to the uws dependency on Windows specifically. I found this comment that may help (make sure you have all these tools installed): nodejs/node-gyp#1056 (comment)

I'm on Linux so it's hard for me to test.

@SSTPIERRE2
Copy link

Hmm I still see the same uwebsockets compile error =/

@Dias999
Copy link

Dias999 commented Jul 21, 2019

Hey guys.. I guess i'm a little late here, but just in case people have the same problem in the future.
I was having the same problem and I found out that my computer's clock was not in sync with the Android's clock.
So to fix it, I just had to set the time of the computer and the Android exactly the same (even the seconds).

@fabOnReact
Copy link

fabOnReact commented Jul 9, 2021

@Dias999

Hey guys.. I guess i'm a little late here, but just in case people have the same problem in the future.
I was having the same problem and I found out that my computer's clock was not in sync with the Android's clock.
So to fix it, I just had to set the time of the computer and the Android exactly the same (even the seconds).

Debugger and device times have drifted by more than 60s. 
Please correct this by running adb shell "date `date +%m%d%H%M%Y.%S`" on your debugger machine.

did not fix the issue.

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

9 participants