This folder contains modern, documented examples for the maintained net472
fork. The old Example, Example2, and Example3 folders are still kept for
compatibility with the original project layout, but they now build with the
current SDK-style project format.
Asynchronous client lifecycle with ConnectAsync, SendAsync, CloseAsync,
callback events, send completion tracking, and a main-thread dispatch queue.
dotnet run --project .\Examples\ClientLifecycle\ClientLifecycle.csproj -- ws://localhost:4649/EchoLoopback echo server with explicit handshake concurrency, pending handshake, frame, message, event queue, and async send queue limits.
dotnet run --project .\Examples\ServerWithLimits\ServerWithLimits.csprojClient-side WSS certificate validation, explicit certificate pinning, compression, proxy, origin, user header, and connection timeout settings.
dotnet run --project .\Examples\SecureAndProxyClient\SecureAndProxyClient.csproj -- --helpSource-only MonoBehaviour example for Unity projects. It is not included in
dotnet build because it references UnityEngine. Copy the source into a Unity
project that already references websocket-sharp.dll.
The example shows how to:
- open with
ConnectAsync; - send with
SendAsync; - close from
OnDisable/OnDestroy; - move websocket-sharp callbacks onto Unity's main thread via
Update(); - keep WebGL excluded because Unity WebGL uses the browser JavaScript WebSocket layer.
Example: interactive console client. By default it connects tows://localhost:4649/Chat; pass a URL argument to target another endpoint.Example2: loopback WebSocket server with/Echoand/Chat.Example3: loopback HTTP server that servesPublic\index.htmland hosts/Echoand/ChatWebSocket services.
Build all console examples from the repository root:
dotnet build .\Example\Example.csproj -c Release
dotnet build .\Example2\Example2.csproj -c Release
dotnet build .\Example3\Example3.csproj -c Release
dotnet build .\Examples\ClientLifecycle\ClientLifecycle.csproj -c Release
dotnet build .\Examples\ServerWithLimits\ServerWithLimits.csproj -c Release
dotnet build .\Examples\SecureAndProxyClient\SecureAndProxyClient.csproj -c Release