Fetch Upload Streaming HTTP/2 Chat (Using Sibal Protocol)
Chat example using HTTP/2 Streaming request and Streaming response.
cd server
npm i -D
npm run watch
Server will serve on https://127.0.0.1:8000, using celf-certificated certs.
cd client
npm i -D
npm run serve
You may need to use chrome canary(> 105). You should go to https://127.0.0.1:8000/ once, and select continue (to ignore security error of self-certificated certificate).
Because browser does not support full-duplex http/2 connection yet, we use two http connections for download and upload.
- Client establishes download stream connection(GET)
- Server generates temporary id for the client and sends it to the client.
- Client establishes upload stream connection(POST) and sends temporary id that received from server.
- Now server knows upload and download stream connection pair for the client.
- Full-duplex connection is established using two stream connections(download, upload).
Why use Sibal Protocol?
Upload and download stream is like tcp socket, fetch upload stream does not guarantee each chunk to be sent separately, of course download stream does not guarantee those thing too. So we need messaging protocol to seperate each message. Sibal is simple protocol to separate each message. It is implemented with Web Streams API, which you can use in both browser and node environment so that you can use it easily.