17 November 2026websocket

Cara Testing Koneksi Web Socket Menggunakan wscat

Web Socket server sudah dideploy, bagaimana cara mengetestnya? Gunakan tool bernama wscat.

Instal wscat menggunakan npm

npm install -g wscat

Jalankan wscat ke alamat URL websocket server yang mau ditest.

wscat -c wss://myapp.com

Jika koneksi berhasil maka muncul pesan Connected. Kemudian kita bisa mengirim pesan interaktif.

wscat -c wss://myapp.com
Connected (press CTRL+C to quit)
< {"event":"pusher:connection_established","data":"{\"socket_id\":\"799068463.946697382\",\"activity_timeout\":30}"}
> ping
< {"event":"pusher:error","data":"{\"code\":4200,\"message\":\"Invalid message format\"}"}
> pong
< {"event":"pusher:error","data":"{\"code\":4200,\"message\":\"Invalid message format\"}"}
>

Jika koneksi gagal maka muncul pesan error: <pesan> dan pesan interaktif tidak bisa dilakukan.

wscat -c ws://localhost:8000
  error: connect ECONNREFUSED 127.0.0.1:8000

Bisakah Test Koneksi Web Socket dengan CURL?

Bisa, tapi terbatas untuk testing websocket handshake saja. Pesan interaktif seperti di wscat tidak bisa dilakukan.

Contoh:

curl -i --http1.1 \
  -H "Connection: Upgrade" \
  -H "Upgrade: websocket" \
  -H "Sec-WebSocket-Version: 13" \
  -H "Sec-WebSocket-Key: xxxx" \
  https://myapp.com

Jika koneksi websocket berhasil, hasilnya seperti ini

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: xxxx

Jika koneksi gagal contoh hasilnya seperti ini.

HTTP/1.1 404 Not Found
Content-Type: text/html

Not Found