Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web socket Ping/Pong and Close control frames implementation

This is my first time to write socket programs and I don't how to implement websocket ping/pong and close control frames in RFC 6455 in C# ( without any third party libraries, I want to implement manually ). Is there someone who has implemented already these control frames in C# or any other programing languages? Please give any sample solutions or correct direction. Thanks a lot!

like image 389
Umidjon Urunov Avatar asked Sep 14 '26 15:09

Umidjon Urunov


1 Answers

Close frames have an op code of 8. You can answer it with a close frame (it will be ignored), but then disconnect.

Pings have an op code of 9. You need to answer any ping with a pong.

Pongs have an op code of 10. Pongs don't need to be answered.

To answer a Ping, the Pong should contain the body of the message sent with the Ping.

Remember a Ping and a Pong can be sent in the middle of a multi-framed message!

You can find a Ruby implementation within The Plezi Framework's Websocket Protocol source code.

I'm sure there are C# implementations as well. @ThomasLevesque suggested WebSocket4Net... maybe that would fit what you're searching for a bit better.

Good Luck!

like image 50
Myst Avatar answered Sep 16 '26 03:09

Myst



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!