Reputation: 4628
A WebSocket ping frame may or may not contain application data in addition to the opcode identifying it as a ping frame.
As far as I understand, the purpose of ping/pong is to prevent the TCP connection from timing out. The frames contain dummy data (i.e. opcodes), as small as possible, sent as frequently as necessary to show that the connection is still being used.
Is there more to it? Would I be missing out on anything if I never sent application data in ping frames? Would I be abusing ping/pong if, for example, I sent tokens in pings in order to establish correspondence between pings and pongs to judge the connection quality by the time between sending a ping and receiving the corresponding pong?
Upvotes: 1
Views: 1895
Reputation: 2760
Ping and pong frames allow a payload that if sent in a ping, will be returned by the corresponding pong. There are several reasons they may not be useful for application data.
That said, all WebSocket implementations compliant with RFC6455 will reply to pings even if they don't let their applications know about them or allow their applications to send their own. This makes using ping/pong and their payloads absolutely appropriate for keepalive messages or other network level statistics or bookkeeping.
Upvotes: 3