So, let's start with why
When you are working with WebSockets it usually means you are working on real-time services, sending back and forth a lot of messages and serving, hopefully, whole bunch of happy users. And you really don't want your real-time service takes long time to respond, or in the worst case scenario, to fail completely and let your users down.
WebSockets are a little bit more complex than standard HTTP, and so is the monitoring for such services. When checking HTTP services for uptime, we usually make one request, measure its time and, if we are more thorough, we check the contents of the response. For WebSockets we always want to know if we can connect to the service, but more often than not, we also want to see if it can send and receive messages.
This is simple: we initiate WebSocket connection to the target endpoint and wait for connection to reach the OPEN state. If we reached this state in predefined time period, test is successful, otherwise it fails.
Image below displays simple WebSocket monitor configured on the UptimeChecker.
Besides connectivity, it is very smart to check if our service functions properly. What means properly can be thousands of definitions for different services, but almost always we must be able to send and receive messages. So, proper test should connect to the service, send message to it, receive response, and close the connection.
If you use UptimeChecker, it is really easy to setup such test: just enable advanced configuration for your monitor, type message to send to the service, type what you are looking for in the response and that's all.
On the image bellow you can see complete test configuration for Echo WebSocket service: we connect to the service (max wait time is 10 000ms), then in the Advanced pane, we define we want to send "testMessage" to the service, and because this is Echo service, we expect to get the same message back. Simple as that!
That is all about WebSockets monitoring in this short intro. If you want to try it yourself, just log in, or sign up if you already don't have an account: UptimeChecker Log In and try it in no time. And, if you have any problems or questions, contact our Support and we will be glad to assist you.