From 5424ea3403df9cd4672290865f12b6f5b01cf2d0 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Thu, 7 Sep 2023 10:09:09 -0700 Subject: Doc updates for v1.0 (#4485) * Remove v0.x messages * Add windows section to Installatino * update * update * Update * Comment out windows --- docs/api/websockets.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'docs/api/websockets.md') 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. -- cgit v1.2.3