How WebSocket works
WebSocket starts as an HTTP request with 'Upgrade: websocket'; after the server agrees, the same TCP connection stays open and either side can push messages at any time - chats, live scores, dashboards.
Layer: Application (OSI layer 7) · Port: 80 / 443 · Transport: TCP · Format: Framed messages · Standard: RFC 6455
WebSocket packet flow
- HTTP Client → App Server: GET /chat Upgrade: websocket
- HTTP App Server → Client: 101 Switching Protocols
- WS Client → App Server: Text frame: {"msg":"hello"}
- WS App Server → Client: Text frame: {"msg":"new message from Ali"}
- WS App Server → Client: Ping
- WS Client → App Server: Pong
Other protocols: HTTP · QUIC · SMTP · IMAP · POP3 · FTP · SMB · WebRTC · SIP · RTSP · RTMP · MQTT · Modbus · PPPoE