Upgrading the connection to WebSocket

  • Admin

    When you want to start communicating with a website via WebSocket you will need to send a request to upgrade from the HTTP protocol to the WS protocol (or equivalently HTTPS and WSS, their secure versions).

    Your request needs to be shaped like this:

    REQUEST GET "https://www.example.com:8081/websocket"
    	HEADER "Connection: Upgrade"
    	HEADER "Cache-Control: no-cache"
    	HEADER "Upgrade: websocket"
    	HEADER "Sec-WebSocket-Version: 13"
    	HEADER "Accept-Encoding: gzip, deflate, br"
    	HEADER "Sec-WebSocket-Key: hQ84EMNKdFvt9OdiGvKffw=="
    	HEADER "Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits"

    You can get the Sec-WebSocket-Key required for secure WebSocket (WSS) by sniffing the request made by your browser during the protocol upgrade.

    After that, you can talk to the server over WebSocket like this (by default it connects via WSS)

    TCP Connect "example.com" "8081" 
    TCP Send "This is now a websocket message!\\r\\n" WebSocket=TRUE
    TCP Disconnect

    Remember to always end your messages with \r\n otherwise the server will listen for the end of the message for an indefinite amount of time.

  • Admin

Log in to reply