Node.js how to respond to an upgrade request?

You just need to call socket.write with the appropriate HTTP syntax as plain text along these lines (from wikipedia):

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
Sec-WebSocket-Protocol: chat

Use \r\n line separators. After that point, HTTP is over and now you are just using the bare TCP socket.

posted @ 2016-12-29 16:48  hdu胡恩超  阅读(153)  评论(0编辑  收藏  举报