diff options
Diffstat (limited to 'docs/api/websockets.md')
-rw-r--r-- | docs/api/websockets.md | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/docs/api/websockets.md b/docs/api/websockets.md index b8b7f7a8e..defc9e18c 100644 --- a/docs/api/websockets.md +++ b/docs/api/websockets.md @@ -12,6 +12,18 @@ Internally Bun's WebSocket implementation is built on [uWebSockets](https://github.com/uNetworking/uWebSockets). {% /callout %} +## Connect to a WebSocket server + +{% callout %} +**🚧** — The `WebSocket` client still does not pass the full [Autobahn test suite](https://github.com/crossbario/autobahn-testsuite) and should not be considered ready for production. +{% /callout %} + +Bun implements the `WebSocket` class. To create a WebSocket client that connects to a `ws://` or `wss://` server, create an instance of `WebSocket`, as you would in the browser. + +```ts +const socket = new WebSocket("ws://localhost:3000"); +``` + ## Start a WebSocket server Below is a simple WebSocket server built with `Bun.serve`, in which all incoming requests are [upgraded](https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism) to WebSocket connections in the `fetch` handler. The socket handlers are declared in the `websocket` parameter. |