Server-Sent Events Demo (No JavaScript Required)

How to Test SSE Manually:

Method 1 - Using curl:

curl -N http://localhost:3000/api/sse-test

Method 2 - Using wget:

wget --no-clobber --output-document=- http://localhost:3000/api/sse-test

Method 3 - Browser Direct Access:

Expected SSE Output:

data: {"type":"connection","message":"SSE connection established","timestamp":"2025-01-19T11:00:00.000Z","counter":0}
data: {"type":"update","message":"SSE update #1","timestamp":"2025-01-19T11:00:02.000Z","counter":1,"data":{"serverTime":"2025-01-19T11:00:02.000Z","randomValue":123,"uptime":123.45}}
data: {"type":"update","message":"SSE update #2","timestamp":"2025-01-19T11:00:04.000Z","counter":2,"data":{"serverTime":"2025-01-19T11:00:04.000Z","randomValue":456,"uptime":125.45}}
...
data: {"type":"close","message":"SSE test completed","timestamp":"2025-01-19T11:00:20.000Z","counter":10}

What to Look For:

  • Connection messages - Should appear immediately
  • Update messages - Should appear every 2 seconds
  • Data format - Should be valid JSON after "data: "
  • Auto-close - Should stop after 10 messages (20 seconds)
  • No errors - Should not show HTTP errors or connection failures

Troubleshooting:

  • No output - Server might not be running or SSE not supported
  • HTTP errors - Check server logs for errors
  • Connection refused - Make sure server is running on port 3000
  • Timeout - Some environments may have connection timeouts

SSE vs WebSockets:

SSE Advantages:

  • Uses standard HTTP (no special protocols)
  • Automatic reconnection
  • Works through firewalls and proxies
  • Simpler to implement
  • One-way communication (server to client)

WebSocket Advantages:

  • Two-way communication
  • Lower latency
  • More efficient for high-frequency updates
  • Binary data support