Ir para o conteúdo principal

How to check the latency of the Socket.IO connection

You can test the latency of your application by sending a ping event to the server and acknowledging it on the other side:


import { io } from "";

const socket = io("wss://");

setInterval(() => {
const start =;

socket.emit("ping", () => {
const duration = - start;
}, 1000);


import { Server } from "";

const io = new Server(3000);

io.on("connection", (socket) => {
socket.on("ping", (callback) => {

Please note that most of the latency will likely come from the network, and not Socket.IO (which has about the same overhead as the underlying WebSocket connection).

The latency can be impacted by a lot of factors, the major one being obviously the distance between the server and the client.

That being said, a client stuck in HTTP long-polling will see a higher latency compared to WebSocket, as the latter keeps an open TCP connection between the server and the client and does not need to send the HTTP headers on each request.