I am new to socket.io and node.js I refered some online documents and created a socket server, it was working fine, but now it shows so many errors, Since I don't know socket.io and node.js I am unable to rectify the problem.
I am receiving the following error in my server side
/home/sitename/public_html/chat-server/node_modules/socket.io/lib/namespace.js:119 fns[i](socket, function(err){ ^ TypeError: Property '0' of object [object Object] is not a function at run (/home/sitename/public_html/chat-server/node_modules/socket.io/lib/namespace.js:119:11) at Namespace.run (/home/sitename/public_html/chat-server/node_modules/socket.io/lib/namespace.js:131:3) at Namespace.add (/home/sitename/public_html/chat-server/node_modules/socket.io/lib/namespace.js:160:8) at Client.connect (/home/sitename/public_html/chat-server/node_modules/socket.io/lib/client.js:76:20) at Server.onconnection (/home/sitename/public_html/chat-server/node_modules/socket.io/lib/index.js:367:10) at Server.EventEmitter.emit (events.js:95:17) at Server.handshake (/home/sitename/public_html/chat-server/node_modules/engine.io/lib/server.js:310:8) at Server.onWebSocket (/home/sitename/public_html/chat-server/node_modules/engine.io/lib/server.js:392:10) at /home/sitename/public_html/chat-server/node_modules/engine.io/lib/server.js:335:12 at completeHybiUpgrade2 (/home/sitename/public_html/chat-server/node_modules/ws/lib/WebSocketServer.js:284:5)
and in the client side I am receiving the following error
GET https://sitename/socket.io/?EIO=3&transport=polling&t=1483766845342-50
and
WebSocket connection to 'wss://sitename:3000/socket.io/?EIO=3&transport=websocket' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
client side code
<script src="https://cdn.socket.io/socket.io-1.3.2.js"></script>
var socket = io();
var socket = io.connect( 'https://sitename:3000',{secure: true,
'sync disconnect on unload': true,'reconnect': true,
'reconnection delay': 500, rejectUnauthorized: false , transports: [
'websocket',
'flashsocket',
'htmlfile',
'xhr-polling',
'jsonp-polling',
'polling'
]} );
server side code
var fs = require('fs');
var app = require('express')();
var https = require('https');
var options = {
key: fs.readFileSync('./privatekey.pem'),
cert: fs.readFileSync('./certificate.crt')
};
var server = https.createServer(options, app);
//var io = require('socket.io')(server);
var io = require('socket.io').listen(server);
var socket = io.use({
transports: [
'websocket',
'flashsocket',
'htmlfile',
'xhr-polling',
'jsonp-polling',
'polling'
]
});
var clients=[];
var gamename={};
var socketid={};
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', 'https://sitename:3000');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
app.get('/', function(req, res){
res.sendfile('index.html');
});
io.on('connection', function(socket){
});
server.listen(3000, function(){
console.log('It is Listening on *:3000');
});
websocket
and see if you learn anything. – jfriend00htmlfile
andpolling
transports? You can't just make up transport names that are not supported in your implementation. – jfriend00