Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ws

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

 ws

情報科学実験A第1部のスライド担当部分

Avatar for Masahiro

Masahiro

May 24, 2026

Other Decks in Programming

Transcript

  1. WSにアップグレードする •GETリクエストをClient •Connection: Upgrade付きのリクエスト がくる GET / HTTP/1.1 Host: 169.254.157.182:10001

    Connection: Upgrade Pragma: no-cache Cache-Control: no-cache User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Mobile Safari/537.36 Upgrade: websocket Origin: http://169.254.157.182:10001 Sec-WebSocket-Version: 13
  2. WSにアップグレードする •WSハンドシェイク •Sec-Websocket-Keyから Sec-Websocket-Acceptを 作って検証する Request Header Response Header Sec-WebSocket-Accept

    の計算 1. クライアントから Sec-WebSocket-Key を受け取る 2. その文字列の後ろに、固定のGUIDを連結する 3. 連結した文字列を SHA-1 でハッシュする 4. SHA-1の結果を Base64 エンコードする 5. それを Sec-WebSocket-Accept として返す
  3. JS対応 •これを足すだけ }else if(pext != NULL && strcmp(pext, ".js") ==

    0){ strcpy(info->type, "application/javascript"); }