NodeJS Packet Loss

NodeJS Logo

A simple web app made with NodeJS as the backend, and vanilla Javascript on the frontend. For the frontend I used the JQuery and SocketIO libraries. The purpose of this web app was to learn NodeJS and SocketIO with a simple idea of simply sending packets to the server and waiting for their responses.

You can view the web app at https://jazyserver.com/packetloss.

Screenshot of web app
Socket.IO Logo

The web app has a very minimalist UI, and two primary features. The default function allows you to send a specific number of packets (pings) to the server and await their response. The original intention of this was to test for packet loss. But due to the nature of HTTP requests and Web Sockets, the connection is made using TCP. Which means that if a packet is lost, it will simply be resent, per TCP’s specifications.

The secondary function can be enabled by checking the Measure Latency box. This will intern change the functionality of the pings, to be sort of relay pings. In that, it will send a ping, then wait for it to return, before sending another. As the name implies, this allows you to measure latency between you and the server.

Demonstration of the measure latency functionality

The code is source controlled on my personal git repository, hosted on my server. Unfortunately, there is no frontend to view the code. At the time of making this web app I was also experimenting with having my own git repository, hosted on my server. I plan on using an open source framework to give my repository a frontend in the future.

The code is relatively simple though. There is no state involved. The server runs on NodeJS, and using SocketIO to listen for incoming connects and then for incoming messages. Once it returns a ping message, it responds with a timestamp so the client can measure any delay. The client uses vanilla Javascript with SocketIO to open a connection to the server. Then depending on the selected functionality, it either simply sends a burst of messages to the server and waits a fixed amount of time for responses. Or sends a message, waits until a response a received, then sends another message, while recording the delay/latency between send and receive.

Thanks for reading 🙂

Leave a Reply