# WebSocket

say it: **“WEB-sok-it”** **/ˈwɛbˌsɑkɪt/**

A connection that stays open for two-way messages, such as chat.

## What is **WebSocket**?

A **WebSocket** is a two-way connection that stays open, so server and browser can send messages at any time. Used for chat and live updates.

```python
@app.websocket('/chat')
async def chat(ws: WebSocket):
    await ws.accept()
    while True:
        text = await ws.receive_text()
        await ws.send_text(f'You said: {text}')
```

Level: Freelancer · [More FastAPI terms at this level](https://www.ask-codey.com/glossary?category=fastapi&level=4)

Updated: November 17, 2026

## In other subjects

- [WebSocket in Web Development](https://www.ask-codey.com/glossary/websocket-web-development)

Source: https://www.ask-codey.com/glossary/websocket
