Not Found error for socket.io on the client-side - node.js

I am trying to include socket.io on the client-side. I keep getting this error message in the console every 5 seconds:
GET https://example.com/socket.io/?EIO=3&transport=polling&t=Lo8ssW0 404 (Not Found)
My code:
script(src='https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.2/socket.io.slim.js')
var socketio = io.connect('https://example.com',{secure: true, port:5089})
On the server-side I have:
const socketio = app.listen(5089)
var io = require('socket.io')(socketio)
which works correctly.
What am I doing wrong?

Simply replace
var socketio = io.connect('https://example.com',{secure: true, port:5089})
by:
var socketio = io.connect()
Does this help? If so, the problem is the host or the port in your original function call.
This simplified code should work, at least if you load the client from the server that runs Socket.io as well.

Related

Error on creating socket server with socket.io on typescript

Im new at socket io and im trying to use typescript on the project so i got the error of the image on start the socket server, i already tried to change the import to import * as socketIo from 'socket.io' but nothing changes, i dont know if is some version issue or im doing something wrong.
the error:
code:
Type declaration for socket.io does not contain default export. You can check it in its index.d.ts. It contains the following:
export { Socket, ServerOptions, Namespace };
That's why to init socket.io server object you need to use the following instruction:
const app = express();
const httpServer = new http.Server(app);
const io = new socketio.Server(httpServer);

Socket.io : How to exclude Flashsocket

I'm using Socket.io 0.9.16 to send notifications to my users.
Everything is working fine, expect for Firefox (version 47). This browser is obviously using the Flashsocket callback and display a nasty warning :
"Firefox has prevented the outdated plugin "Adobe Flash" from running..."
1) Why the last version of Firefox is using Flashsocket as a callback, and not websocket ?
2) I don't want to use Flash at all. I tried to disable Flashsocket by setting which transports I want to use:
Client JS :
var socket = io.connect('myIP:XXXX',
{transports : ["websocket", "xhr-polling", "htmlfile", "jsonp-polling"]});
Server JS :
var io = require('/Path/TO/socket.io').listen(XXXX);
io.configure(function () {
io.set("transports", ["websocket", "xhr-polling", "htmlfile", "jsonp-polling"]);
io.set("polling duration", 10);
});
io.sockets.on('connection', function (socket) {
etc...
But what I did above is not working. Firefox continues to use Flash and shows the warning (as Chrome is using websocket all right)
Do you have any idea what I'm doing wrong ?
PS : I know socket.io v1.x is not using Flash as a callback anymore so it would be solution to upgrade, but I can't just figure out how to adapt my script to make it work with the v1.x version, so I'd like to stay with v0.9.16 if it possible.
Thank you for your help!
I had same problem, but updating version of socket.io and node solved the problem. Sample code given below:
Client JS
socket = io.connect('ip:port', {transports : ["websocket", "xhr-polling", "htmlfile", "jsonp-polling"]});
Server JS
var http = require('http');
//creating server
var server = new http.createServer();
//setting server listening port and domain
server.listen(PORT, DOMAIN);
var io = require('socket.io').listen(server, {transports: ["websocket", "xhr-polling", "htmlfile", "jsonp-polling"]});

Trying to use Socket.IO namespaces causes 404 polling error

When I use Socket.IO to connect like normal/default
var client = io.connect('http://localhost:466/');
It works/connects just fine. No errors in console.
However, when I want to try connecting to a namespace like so
var client = io('/adm').connect('http://localhost:466/');
I get the following errors
The admin namepsace is created on the server
//start server
var server = require('socket.io').listen(466);
//admin namespace
var adm = server.of('/adm');
adm.on('connection', function(client){
console.log('adm connection');
});
The issue was that I was trying
var client = io('/adm').connect('http://localhost:466/');
instead of
var client = io.connect('http://localhost:466/adm');
Which I find odd, because the documentation seemed to recommend the first method.
http://socket.io/docs/rooms-and-namespaces/#custom-namespaces

Socket.IO connection error

I've an application in node.js with socket.io. Everything was running completely fine, but suddenly the browser started to send this error.
failed: Error in connection
establishment:net::ERR_TUNNEL_CONNECTION_FAILED
I didn't make any code change.
The protocol used by socket is ws:// and when I try to use this url in browser
'ws://highgarden-nodejs-91180.sae1.nitrousbox.com/socket.io/?EIO=3&transport=websocket&sid=T9Unec8KbWw-GAL8AAAF'
Chrome returns this error:
Failed to load resource: net::ERR_DISALLOWED_URL_SCHEME
This is a part of the socket setup code:
server.js:
var app = express();
var server = http.createServer(app);
var io = require('socket.io').listen(server);
var port = process.env.PORT || 3000
*------------------------------------------*
// routes ===
var routes = require('./config/routes.js');
var sock = {}
routes(app, passport, sock);
io.sockets.on('connection', sock.update);
// launch ===
server.listen(port);
Thanks advance.
Hi the exception ERR_TUNNEL_CONNECTION_FAILED happens when a tunnel connection through the proxy could not be established. And the ERR_DISALLOWED_URL_SCHEME happens when the scheme of the URL is disallowed.
May you need use it behind the proxy!
Chrome 45.0.2454.101 m says the page has been disabled or moved on the server.

AppFog node.js client cannot load socket.io

I just deployed a node.js site to AppFog. It works fine locally when I go to "http://localhost:8080", but when I got to the one on AppFog: http://bandwithfriends.aws.af.cm/ I get the following Chrome console error:
XMLHttpRequest cannot load http://localhost:8080/socket.io/1/?t=1357769454152. Origin http://bandwithfriends.aws.af.cm is not allowed by Access-Control-Allow-Origin.
SERVER CODE:
var app = require('http').createServer(handler),
io = require('socket.io').listen(app),
static = require('node-static'); // for serving files
// This will make all the files in the current folder
// accessible from the web
var fileServer = new static.Server('./');
app.listen(process.env.VCAP_APP_PORT || 8080);
io.configure('development', function(){
io.set('transports', ['xhr-polling']);
});
CLIENT CODE index.html:
I am including socket.io like this:
<script src="/socket.io/socket.io.js"></script>
CLIENT CODE script.js:
var url = 'http://localhost:8080';
var socket = io.connect(url);
How do I fix this?
All I had to do to fix this was remove the url on the client side code:
var socket = io.connect();
Hope this helps anyone else having the same problem!
Both your client side and server side are wrong.
On the client side; make this change:
var url = io.connect('http://<your domain name>');
//For example: var url = io.connect('http://shash7.ap01.aws.af.cm');
On the server side, you need to implement socket.io like this:
var app = require('express')() , server =
require('http').createServer(app) , io =
require('socket.io').listen(server);
server.listen(80);
The above code was taken from the socket.io site. They changed the way socket.io listens in the 0.9 version so use the above version.
Other than that, everything looks fine. Tell me if you still can't figure this out.

Resources