admin管理员组文章数量:1277338
I'm handling a websocket 'upgrade' event from a Node.js http server - The upgrade handler is in the form function(req, socket, head) - How can I send a response to this upgrade request given that there is no res object? Is there a way to do it using the socket object? How to send back headers?
I'm handling a websocket 'upgrade' event from a Node.js http server - The upgrade handler is in the form function(req, socket, head) - How can I send a response to this upgrade request given that there is no res object? Is there a way to do it using the socket object? How to send back headers?
Share Improve this question asked Aug 4, 2013 at 17:02 JonJon 1,3142 gold badges14 silver badges24 bronze badges 2- Why do you use the http server for websockets? There are plenty of dedicated libraries. And yes, you're supposed to answer via the socket. – Bergi Commented Aug 4, 2013 at 18:31
- I'm writing a custom proxy for engine.io. The node-http-proxy library (by Noejitsu) does not appear to work with engine.io - I just want to get the basic logic working at this stage. – Jon Commented Aug 4, 2013 at 21:46
1 Answer
Reset to default 10You 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.
本文标签: javascriptNodejs how to respond to an upgrade requestStack Overflow
版权声明:本文标题:javascript - Node.js how to respond to an upgrade request? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741291971a2370602.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论