ERR_CONNECTION_REFUSED http://localhost:3000/socket.io/socket.io.js - javascript

Ciao, I'm implementing a webRTC many-to-many videoconferencing system, actually, I already did it, I am using socket.IO as signalling server, and everything goes super well, I am using EnterpriseDB Apache for serving my .html file on port (8081) and Node.js for serving socket.IO on port (3000), It is working like charm in localhost, no errors, My ISSUE is serving for external access with my public IP, I am testing with my friends and these browsing services: www.browserstack.com and www.browserling.com (trial versions).
with www.browserstack.com, everything is working fine with either mozilla 42 or chrome 47
with www.browserling.com, I got these errors
Firefox 41: ReferenceError: io is not defined
Chrome 45: Failed to load resource
http://localhost:3000/socket.io/socket.io.js
net::ERR_CONNECTION_REFUSED
Uncaught ReferenceError: io is not defined
with my friends, I am having the same issues as www.browserling.com, but they are using the latest browser versions (Chrome 47 and Firefox 42) for connecting to my PC server.
I think this is not a browser version issue, The issue is on serving the socket.io.js file, finally, here is my code:
It shows just the important things in order to solve this problem:
///NODE.JS DIRECTORY
////////////////////serverside.js
var port = 3000;
var io = require('socket.io').listen(port);
io.sockets.on('connection', function (socket){.........}
///APACHE DIRECTORY
////////////////////clientside.js
//Connect to signalling server
var socket = io.connect("http://localhost:3000");
////////////////////avq.html
<!DOCTYPE html>
<html lang="es">
<head><meta charset="UTF-8">
</head>
<body>
<script src="http://localhost:3000/socket.io/socket.io.js"></script>
<script src="js/clientside.js"></script>
</body>
</html>
this is my server URL if anyone wants to try:
http://201.209.104.33:8081/webrtcexamples/avq.html

localhost is a special host name that points to the same computer as the one requesting it. So anyone using a different computer than yours and trying to connect to localhost will try to connect to its own computer, not yours. As the server is not running on their computer, they quite obviously get a "connection refused" error.
You need to replace localhost with a globally accessible address (domain name or IP address). This also implies that you need to have your router map your external IP address to your computer running the server for this port (otherwise they will connect to your router, not your server).

try io.connect("http://201.209.104.33:3000"); instead of io.connect("http://localhost:3000");
EDIT
You need to run the socket on the server that it is being used. So if you run it on your PC, your friends pc will not see it, because when it connects to localhost, it will try to connect to the localhost of THEIR pc. Not yours.
I had the same issue before. You need to run it off of the server so that everyone can connect to it.

Related

Web socket connection does not work over SSL

I have Web Socket that works perfectly fine on localhost and production (https://www.example.com) environment.
However, when I deploy the same code to pp environment (https://pp.example.com) I get WebSocket handshake: Unexpected response code: 404
I have AWS certificate manager generated certificate for domain example.com, with additional domain name www.example.com and pp.example.com
www.example.com and pp.example.com are sitting on different server so they have different ip addresses.
When I go to www.example.com and make the following call,
let ws = new WebSocket("wss://www.example.com/ws");
It works perfectly fine.web socket is connected.
However, when I switch to pp.example.com and make the following call
let ws = new WebSocket("wss://pp.example.com/ws");
I get error from Safari, Firefox and Chrome:
WebSocket connection to 'wss://pp.example.com/ws' failed: Error during
WebSocket handshake: Unexpected response code: 404
Any ideas?
The code are exactly the same.
They are deployed on aws beanstalk.
production environment is using global accelerator + application load balancer + EC2
pp environment is using classic load balancer + EC2
The problems lies in load balancer's listener.
I was using HTTPS for traffic forwarding, while web socket works on TCP level, therefore, it should be SSL TCP instead.
See the attached screenshot at the following for load balancer

How to connect frontend and backend on domain

I don't really have experience with backend and how things work together. I have created a simple live message sending app with node.js and socket.io. When I host a static web server on my machine (http-server which runs on local port using node.js) my app works perfectly fine but when I upload it on my host or github pages just for test, the backend doesn't seem to work. I uploaded all my files with an FTP program and the frontend loads fine but the backend doesn't. Do I have to know something like Django or ASP.NET to make these work on my host?
EDIT: One more thing, first line in my server.js is const io = require('socket.io')(3000)and in my script.js - const socket = io('http://localhost:3000')where 3000 and localhost:3000 stands for local host in my machine. What do i need to put instead of these?
You probably need to install and setup Node.js on your server, contact yout hosting provider for node installation if the option isn't available in yout cPanel.

Sockets Connecting

I have been trying to get my WAMP Webserver run with socket.io but I just cannot seem to get it to work.
My socket server is on port 3000 and the WAMP on port 80. I know that both servers work.
Web Server Client Code:
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io('http://[ip address]:3000');
socket.on('buzz', function (data) {
console.log(data);
});
</script>
Console Error:
Uncaught ReferenceError: io is not defined
at (index):97
UPDATE
I was missing the socket.io.js file. But now I am getting
GET http://[[IP]]:3000/socket.io/?EIO=3&transport=polling&t=LxfQwpE
net::ERR_CONNECTION_TIMED_OUT
In the console every few seconds.
As I recall, this problem was solved by installing a NGINX reverse proxy -- I believe I followed the instructions here: Socket.io with nginx
This was one of my first projects, but I thought I would point people in the right direction in case other students wish to use a WAMP backend and Socket.io.

Kurento Media Server HelloWorld Javascript example webSocket error

Merry Christmas!
I am trying to configure KMS on my Ubuntu 14.04 (64 bit). I could install the KMS server successfully following the guide at https://www.kurento.org/docs/6.0.0/installation_guide.html.
Also, downloaded the Javascript HelloWorld tutorial from https://www.kurento.org/docs/6.0.0/tutorials/js/tutorial-1-helloworld.html. I could run the example successfully on localhost on Google Chrome Version 47.0.2526.106 (64-bit) on the same Ubuntu System.
But, I could not see the local video nor the loop backed video. Only a spinner icon is shown on both the Video placeholders. Consulting the Console log reveals a problem after creating the SDP offer. The error is as described below.
kurento-client.js:21072 WebSocket connection to 'wss://127.0.0.1:8433/kurento' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
I am no expert on web sockets and stuff. Any help on this would really help me to proceed forward.
Note: I am running the example on HTTP, not on HTTPS. I guess that would not be the cause of the problem, though.
Regards,
LazyCoder7
I managed to solve it. I was wrong on my guess though, HTTPS was indeed required in order to make the WebSocket connection ( i was not aware of that part ). Created a certificate file (.pem) (from crt and key file already in the helloworld folder) and configured the KMS server to use the certificate. After this I was able to see myself and the same me in loopback :)
You are following an old version of the documentation. Since Chrome 47, in is mandatory to server pages through HTTPS if you want to use the getUserMedia APi. So we updated all our tutorials, and they now have a self-signed certificate. In case of the JS tutorials, you also need to configure KMS to expose a secure WS signalling connection, as the browser directly connects to the media server to control it.
Please follow the latest version of the documentation here
Be sure that the KMS is running on the port 8433 (not 8888), if you are using docker
docker run -d --name kms -p 8433:8433 kurento/kurento-media-server:trusty-latest

socket.io/socket.io.js stuck on (pending) - Node.js

So whenever I check if the /socket.io/socket.io.js file is loaded onto my webpage is says (pending) and after a while (failed) net::ERR_CONNECTION_REFUSED
I've been looking through some other posts and trying some stuff.
I've tried using <script src="/socket.io/socket.io.js"></script>
and <script src="http://127.0.0.1:8080/socket.io/socket.io.js"></script>
My original code includes <script src="http://10.0.0.199:8080/socket.io/socket.io.js"></script> where 10.0.0.199 is my server which is running node.js and mongoDB.
My full code of my server.js file is as follows: (this file starts the socket.io)
var mongo = require('mongodb').MongoClient,
client = require('socket.io').listen(8080).sockets;
console.log('info - socket.io started');
Do not try to import Node JS script on web page
You can not play directly with socket in JS under Web Browser. Currently web browsers support only websockets.
Apparently my firewall somehow managed to block the 8080 port again.
I used iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT -m comment --comment "Socket.io port" to open the port on my firewall but this did not help. I managed to open the port using the GUI on my server.
Thanks everyone, and I hope that this might help someone in the future as this was very confusing.

Categories