持久连接的基本客户端-服务器设计?
据我了解,这是:
Client &服务器建立连接
客户端发送服务器数据
服务器解释数据,发送客户端数据
依此类推,直到客户端发送断开信号。
我只是想知道实施情况。第2步和第3步让我感到困惑,也许我把它弄得太复杂了。除了巨大的 switch 语句之外,还有其他解释数据的方法吗?
有什么关于客户端/服务器设计的好书吗?具体谈论多线程服务器、可扩展性和消息设计(字节 1 = 标头信息,字节 2 = 等等)?专门针对 C++。
Here's as far as I understand it:
Client & Server make connection
Client sends server data
Server interprets data, sends client data
So on, and so forth, until client sends disconnect signal.
I'm just wondering about implementation. Step 2 and 3 are confusing to me, maybe I'm over-complicating it. Is there anymore to interpreting the data than a giant switch statement?
Any good books on client/server design? Specifically talking about multithreaded servers, scalability, and message design (byte 1 = header info, byte 2 = blah blah, etc)? Specifically geared towards C++.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会考虑数据包、数据包类型、数据包标识符和数据包类型处理程序的存储。
一个想法是仅以数据包的形式发送数据。每个数据包在开头都保存其标识符(可选)和类型(长度也很有用),连接的每一侧都有一堆数据包处理程序,每个处理程序管理相应类型的数据包(读取和解释)。如果您发送数据包长度,您甚至可以跳过不支持的数据包类型,从而允许不同的客户端和服务器版本。
I woould think about packets, packet types, packets identifiers and storages of packet types handlers.
An idea is to only send a data in form of packets. Each packet holds its identifier(optional) and type at the beginning (length would be useful too) you have a bunch of packet handlers on each side of connection each handlers manages packets of corresponding type (reads and interprets). If you send a packet length you can even skip usupported types of packets allowing differrent client and server versions.