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

协议设计的一些想法 #8

Open
bg5sbk opened this issue Dec 3, 2015 · 6 comments
Open

协议设计的一些想法 #8

bg5sbk opened this issue Dec 3, 2015 · 6 comments

Comments

@bg5sbk
Copy link
Contributor

bg5sbk commented Dec 3, 2015

目前的设计是初始化连接时用换行文本协议,如果初始化失败则回发二进制的错误码。

我在想,既然初始化已经用到文本协议了,何不连状态码返回也一起用文本协议,反正状态码也没几个字节。

还有一点是连接成功没有成功对应的状态码返回。

如果连接成功失败都有文本的状态码返回,就可以比较方便的用telnet做测试,手工发送一条连接初始化信息,在telnet可以直接看到服务端回发什么数据。

另外,是否需要在开头加个协议版本号,方便将来协议升级向下兼容不同版本的客户端?

@tomasen
Copy link
Contributor

tomasen commented Dec 4, 2015

计划上行第一个字节做协议类型来实现兼容。

但是返回文本的状态码没见到过先例吧。有看到什么项目这样做的例子么

@bg5sbk
Copy link
Contributor Author

bg5sbk commented Dec 4, 2015

websocket协议的握手过程就是双方互发文本,握手完成后后续使用二进制协议。

@bg5sbk
Copy link
Contributor Author

bg5sbk commented Dec 4, 2015

The handshake from the client looks as follows:

    GET /chat HTTP/1.1
    Host: server.example.com
    Upgrade: websocket
    Connection: Upgrade
    Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
    Origin: http://example.com
    Sec-WebSocket-Protocol: chat, superchat
    Sec-WebSocket-Version: 13

The handshake from the server looks as follows:

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

@bg5sbk
Copy link
Contributor Author

bg5sbk commented Dec 4, 2015

同时带了版本信息

@tomasen
Copy link
Contributor

tomasen commented Dec 13, 2015

[4ecd323]

并开始支持WebSocket

@cupen
Copy link

cupen commented Feb 28, 2024

这代码几乎有 10 年了,似乎已经不再用于生产环境。@tomasen 还在心动不?

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

3 participants