Here some example from my tutorial on "How to Build a Web Server"
- WebSocket on Arduino, esp8266 and esp32: client
- WebSocket on Arduino, esp8266 and esp32: server and authentication
- WebSocket on Arduino, esp8266 and esp32: update temperature and humidity project
Check the documentation on the site to undestand the code and behavior of the examples.