Node.js, WebSocket Location Issue? - node.js

I created a server using Node listening on port 8000, localhost. Verified it's running properly, but I cannot access the WebSocket on the client (Chrome 5). Tried several implementations from various Git repos, node + websocket, socketIO, articles, etc. Nothing.
No port conflicts (sudo lsof -i tcp);
Tried server.listen(8000, "*");
Pointed to ws = new WebSocket("ws://:8000/test");
Debian Lenny, Apache22
Node v0.1.98-31-g1c6671a
I'm thinking there may be a conflict with url rewrite. Or possible permissions. Any ideas?

I had a similar issue on Ubuntu 10.04 LTS 32-bit and Chrome 5.0.375.125 and found out it is a bug in Chrome.
Here's how you can test and work around the problem. I used WebSocket with PHP and later Node.JS:
PHP: Download a tutorial file from http://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/ and extract it in a folder called 'socket' in your webroot. This folder now contains a readme.txt and the folders 'server' and 'client'. Now start the script in the console according to the readme (for me the command was: sudo php -q /var/www/socket/server/startDaemon.php ). It should print 'Start listening on Socket.' . Leave the console window open. Now go to localhost/socket/client/client.php in Chrome. It should say 'Socket Status 0' and if you look in the console you see no new messages (no connection was made).
Now here comes the trick: open a second Chrome tab. Point this tab to the same url: localhost/socket/client/client.php (It also says 'Socket Status 0'). And then close it again. Your original tab should now say 'Socket Status: 1 (open)' and in the console you see a handshake was made. WebSocket now works.
I repeated the same trick as above but this time using Node.JS with the Socket.IO script. The chat example included in Socket.IO-node ( github.com/LearnBoost/Socket.IO-node ) had the same issue, hanging at the 'Connecting...' stage. Opening a second tab to the chat box and then closing it again solved the problem and the chat box proceeded to load properly. The Node.JS server confirmed the connection in the console. From then on WebSocket worked fine.

Related

Django's 'python manage.py runserver' does not create a local website I can access

I am trying to follow this online class, and I am stuck on the part where I access a local website made by django. The tutorial that I follow is this one by freecodecamp, and I get stuck by the 11min mark where I try to access the output site http://127.0.0.1:8000/ . I am following this tutorial on the browser version of Jupyter Notebook.
Tutorial: https://www.freecodecamp.org/news/create-an-e-commerce-site-with-django-and-vue/
The 'python manage.py runserver' line runs, and I get the following output:
System check identified no issues (0 silenced).
April 16, 2021 - 03:37:04
Django version 3.2, using settings 'djacket_django.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
When I copy and paste the server address into the browser, I just get the following error saying that I wasn't able to connect to the site:
Unable to connect
Firefox can’t establish a connection to the server at 127.0.0.1:8000.
The only resource I really found that addressed this issue was the following post, but when I went through my netstat list, there were no IPs listing :8000, so I don't think that I am using up that address already.
Post:
Django manage.py runserver is not working
Sounds like you are using WSL2 and have not yet discovered that the WSL2 VM's IP address is not the same as the Windows IP address. Windows has its own idea of what localhost might be!
TL;DR: Use GWSL to run WSL2 apps on X Windows. This will allow you to run a browser from WSL2 over X Windows, and no worries.

electron+figwheel on Mac causes websocket connection error

Background
I am trying to integrate figwheel with electron(atom-shell). I use
lein new figwheel hello-world -- --reagent
to generate figwheel part, and copied the electron part from electron quick start. The resulting project is here.
Question
Run the project by:
Open a terminal and start figwheel lein figwheel
Open another terminal, start Electron by electron ..
However it fails on Mac. The electron part shows the following log:
[5848:0720/220633:INFO:CONSOLE(62)] "WebSocket connection to 'ws://localhost:3449/figwheel-ws/dev' failed: Connection closed before receiving a handshake response", source: file:///Users/foo/repos/cljs-douban/resources/public/js/compiled/out/figwheel/client/socket.js (62)
[5848:0720/220635:INFO:CONSOLE(82)] "Figwheel: trying to open cljs reload socket", source: file:///Users/foo/repos/cljs-douban/resources/public/js/compiled/out/figwheel/client/utils.js (82)
However, the same project works on Linux. Googled and no correct result, Please kindly help.
After googled for 'MAC websocket connection error', I got a similar problem here.
And it is the proxy I set screwed 'localhost', which causes connection error. Disable the proxy fixed the issue. Sorry for any inconvenience.

Selenium testing setup on remote server

I'm trying to install and run Selenium on a remote server to run web tests for a Drupal 7 install. I need to find a way for the browsers installed on the server to output their display onto the computer that is connected to the server, and I need to figure out why Selenium is failing to run. Error messages down below.
My server set up:
centOS 7.1 on Linux running NGinX web server
X11Forwarding available and enabled
Drupal 7 install
Selenium 7.x-3.0 Drupal Module
Selenium Standalone Server 2.46.0
Firefox 38.1.0 installed
Google Chrome stable 43.0.2357.132
Chromedriver 2.16 for 64-bit Linux, set to executable, with symlink to driver in /usr/bin and /usr/local/bin (the local is the only necessary one, the usr/bin is just a fallback)
Note: my solution must have the server hosting the selenium server as the website will be delivered to a client when it's ready for production. It won't work for me to just install the selenium server and browsers on my own machine.
My issues:
When I ssh -X user#server, it doesn't seem to matter what I set the DISPLAY to, firefox can't open the display when I run 'firefox &' [e1]. I've tried export DISPLAY=localhost:0.0, localhost:10.0 and [myIP]:0.0/10.0.
When I run the selenium server and attempt to run the sample test cases on my website, the Firefox instance of the test fails to connect through 127.0.0.1 port 7055 [e2] and the Chrome instance is either unable to find the driver or shuts down unexpectedly [e3]
Errors:
e1 - Error: cannot open display: host:#.# <== (Whatever variant I've attempted)
e2 - Message: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output: (blank)
e3 - Message: chrome not reachable
SimpleTest isn't a suitable replacement as the things I'm trying to test require too much custom setup to configure a stock Drupal sandbox properly. Consequently, I'm relying on Selenium's option to test on the original site instead of a sandbox.

Node.JS code fails without error on Ubuntu

I have the simplest code for firebase :
var Firebase=require('firebase');
var Ref=new Firebase('http://mydb.firebaseio.com/requests');
Ref.push({name:"checkin",type:"mandatory"},function(response){
console.log(response);
});
and I'm running it with SSH in command line on my Ubuntu 12.04 server. For some reason the push method runs but doesn't push anything and doesn't even show an error. I tried logging the error to a file but the file remains empty. I also tried catching an uncaught exception from the process, no luck. There basically isn't an error to show. How should I catch an error so I can investigate further ?
Extra information :
-Node.JS version installed on the server is 12.4 .
-One thing I noticed is there is no certificate file on the server and for example I can't use curl with an https url or PPA to download a package.
-Ubuntu 12.04.
-When I push to firebase using a PHP script it works fine but nodeJS fails to do it.
-The server is in a hospital's internal network and connects to internet through a proxy. Certain HTTPS websites are allowed on port 80 , the rest are blocked . Some similar policies might be in place for other ports and protocols.

Getting the node.js monitor-dashboard project to work externally

I'm trying to get the monitor-dashboard project to work but i get a page can't be found error when I try to use a browser externally.
http://lorenwest.github.io/monitor-dashboard/
Internally seems OK, I'm getting a HTTP/1.1 200 OK from http://localhost:4200 with the usual curl command.
I went in to node/node_modules/monitor-dashboard/config/, and changed default.js and external.js and changed all occurrences of allowExternalConnections to true.
I've also got node-monitor loaded in to my node project.
I'm running node server.js first and then npm start monitor-dashboard in another window.
port 4200 is open via iptables -L
Any ideas?
The setting you're looking for is:
export NODE_ENV=external

Resources