Simple WebSocket Test on the Server Side

By | May 20, 2021

WebSocket protocol is a suitable way to create a reliable two directional connection between a server and a client. WebSocket is using the same ports as HTTP/HTTPS protocols: 80 and 443. However very frequently WebSocket is not such transparent as HTTP and may be blocked by firewalls, proxy or antivirus applications.
Anyway if multiple WebSocket clients do not work better to start testing from the server side and it is an example of local WebSocket server test. The test using wget command, but the same it is possible to do with curl or other CLI web clients.
Here is the wget command itself:

wget -d --no-check-certificate \
   --header "Connection: Upgrade" \
   --header "Upgrade: websocket" \
   --header "Host:" \
   --header "Origin:" \
   --header "Sec-WebSocket-Key: " \
   --header "Sec-WebSocket-Version: 13" \

In your case WebSocket URL may be different, check what URL is used by WebSocket client and replace external IP/fqdn with

If WebSocket on server side works normally the HTTP response should contain code 101 which indicates that server accepted request to switch protocol from http/https to ws/wss (WebSocket/Secure WebSocket), example of such response:

—response begin—
HTTP/1.1 101 Switching Protocols
x-frame-options: SAMEORIGIN
connection: Upgrade
sec-websocket-accept: qGEgH3En71di5rrssAZTmtRTyFk=
upgrade: WebSocket
uuid: 6c2b496e-e4ac-4bc0-b30d-4197d9ddae5e
—response end—

It the case if something is going wrong the response code may be different for example 405 (Method Not Allowed):

—response begin—
HTTP/1.1 405
x-frame-options: SAMEORIGIN
cache-control: must-revalidate,no-cache,no-store
content-type: text/html;charset=iso-8859-1
content-length: 502
date: Thu, 20 May 2021 13:24:47 GMT
server: LiteSpeed
uuid: 0840b565-e211-4438-a2c9-925ab322e736
—response end—

Leave a Reply

Your email address will not be published. Required fields are marked *