Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

websocket #46

Open
zonglang opened this issue Sep 6, 2019 · 0 comments
Open

websocket #46

zonglang opened this issue Sep 6, 2019 · 0 comments

Comments

@zonglang
Copy link
Owner

zonglang commented Sep 6, 2019

websocket实现了全双工实时通信
本身tcp协议就是可以全双工实时通信的,但是http协议的请求-应答机制限制了全双工通信;
首先通过http的get请求,进行协议升级,前端和服务端商量着绕过http协议

// 请求头
GET ws://localhost:3000/ws/chat HTTP/1.1
Host: localhost
Upgrade: websocket
Connection: Upgrade
Origin: http://localhost:3000
Sec-WebSocket-Key: client-random-string
Sec-WebSocket-Version: 13
// 响应头
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: server-random-string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant