This project demonstrates a simple yet robust WebSocket server and client implementation using .NET.
- Server: ASP.NET Core Minimal API handling WebSocket connections at
/ws. - Client: Console application for interacting with the server.
Overall Flow: Client ➔ TCP Handshake ➔ HTTP Upgrade Request ➔ Server ➔ 101 Switching Protocols ➔ WebSocket Established ➔ Data Exchange
Add the following to your Nginx site configuration (/etc/nginx/sites-available/default):
server {
listen 80;
server_name example.com;
location /ws {
proxy_pass http://localhost:5000/ws;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
# Timeout settings for long-lived connections
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
}
}In WSL:
# 1. Start the Server
cd Server
dotnet run
# 2. (In another WSL terminal) Start the Client
cd Client
dotnet run