Skip to main content

NodeJs - Socket.IO Set Ping Timeout & Ping Interval | node-js-tutorial.blogspot.in


How to Socket.io Specifying Heartbeat

Here we Learn Method of Set Ping Timeout & ping interval.
There Are Several Way to Set Ping interval & Ping Time out.


Please Remember Some note : ping interval is alway small then ping Timeout.
Always Set Same ping timeout & ping Interval for both side. (Client side  & Server Side) When You Develop any Client Server Application.


Following Are some Pattern Which most Case Peopele use.

1) Type One 

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http, {
'pingInterval': 2000,
'pingTimeout': 5000
});



2) Type Two

For package dependency versions:

"express": "^4.12.3",
"socket.io": "1.0"

ex :

var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);

io.set('heartbeat timeout', 5000);
io.set('heartbeat interval', 2000);



3) Type Three

When we Define Config File for socket.js

[{
   pingInterval: 2000,
pingTimeout: 5000

}]



Thanks.

Comments

  1. The Best of the Node JS Blogs You have Mentioned here.
    MEAN Stack Training in Hyderabad

    ReplyDelete
  2. Thanks for sharing the useful blog about Set Ping Timeout & Ping Interval in Socket.IO Package of Node JS.

    Custom Web Application Development Company in Coimbatore

    ReplyDelete
  3. Thank you for sharing such a nice and interesting blog with us.
    Full Stack Online Training

    ReplyDelete
  4. The information which you have provided is very good. It is very useful who is looking for
    Best nodejs Training Institute

    ReplyDelete
  5. Enjoyed reading the article above, really explains everything in detail, the article is very interesting and effective. Thank you and good luck for the upcoming articles learn Node JS training

    ReplyDelete
  6. Thanks for this post this is a very useful post , For more information about the Nodejs development company here is the list of Top 10 Node.js Development Companies . Thanks for the post .

    ReplyDelete
  7. Hiii.....Thanks for sharing Great information....Nice post....Keep move on....
    Angular JS Training in Hyderabad

    ReplyDelete
  8. What a brilliant information you are sharing here about the relevant technology. I really appreciate your effort. I’ll visit your blog again to get some more nice information about other technologies too. Keep up the good work buddy!!

    Node js Development Company Texas

    ReplyDelete
  9. ExpressTech Software Solutions is a nodejs Development Company, where we provide the leading Node JS web development services to our clients across the globe. Contact us: +91-9806724185 or Contact@expresstechsoftwares.com

    ReplyDelete
  10. Enjoyed reading the article above, really explains everything in detail, the article is very interesting and effective. Thank you and good luck for the upcoming articles nodejs training

    ReplyDelete
  11. It has been great for me to read such great information about Node JS. Keep on sharing.
    Node JS Online training
    Node JS training in Hyderabad


    ReplyDelete

Post a Comment

Popular posts from this blog

How to Use MongoDb Nativ Query With Model in NodeJS | node-js-tutorial.blogspot.com

How to Use MongoDb Nativ Query With Model in NodeJS | node-js-tutorial.blogspot.com In this artical, you have learn how to use mongo native query with node model. let understand some code. Following code use for conver Sting To Object ID. Declare in top of Your code. var ObjectId = require('mongodb').ObjectID; Nativ query Understand Object Id not String. let userId = '123232323232'; // ID of User. Your_Model.native(function (err, modelObj) { modelObj.update({ "_id": new ObjectId(userId) }, { $push: { <feild>: { <feild>: <value> } } }, function (err, res) { if (err) { // Print Error Log console.log(err); } else { // Print Success Log console.log(res.result); } }); }); // End Nativ Here Que...

Soket.io Use Of Ping Pong Events | node-js-tutorial.blogspot.in

When we Create Client Server Application, Some time we Need To Check out Live Connectivity between Client & Server. Let's we Understand by Example, Server Code. const fs = require('fs'); const http = require('http'); const path = require('path'); const SocketIOServer = require('socket.io'); const app = new http.Server(); app.on('request', (req, res) => { const index = path.join(__dirname, 'public', 'index.html') fs.readFile(index, function (err, data) { if (err) { res.writeHead(500); return res.end('Error loading index.html'); } res.writeHead(200); res.end(data); }); }); app.listen(3000, 'localhost'); const io = new SocketIOServer(app); // could also use "connection" io.on('connect', function (socket) { console.log(`${socket.id} "connect"`); socket.on(' ping ...