关于使用c ++的websocket服务器实现 [英] Regarding websocket server implementation using c++

查看:671
本文介绍了关于使用c ++的websocket服务器实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在c ++中开发websocket服务器实现的步骤是什么?

What are the steps to develop websocket server implementation in c++??

推荐答案





这很容易。实际上,有很多可能性。基本上:

1)使用低级函数 - 如果你编写好代码,我们可以在Windows和Linux之间移植。

2)使用一些库 - 这个解决方案可以(但不一定是)便携式。





所以:

如果你想使用shell学习函数的最佳选项 socket 绑定听取accept 。这些函数通常由TCP服务器调用,以便开始等待和接受连接。你会发现很好的例子如何在上面的链接中使用这些功能。但是,请注意HTTP协议是一种文本协议,因此您必须解析所有可能的HTTP请求,并在您的代码中发送所有可能的HTTP响应。写作真的很乏味!!!



也许我会建议使用一些准备好的库或API。如果要为Windows编写服务器应用程序,可以使用 WinInet API



但是,不要忘记让你的服务器多线程,以便它可以同时为许多客户端请求/连接提供服务。这将需要为每个传入的客户端连接创建一个线程。该线程将为客户端服务,然后终止。这是一个相当困难的话题,如果你是一个初学者,但如果你想了解它,你可以在MSDN文档中找到一些好的信息。



最好的问候,

JK
Hi,

This is quite easy. Actually, there are severela possibilities. Basicly:
1) Use low level functions - if you write your code well, it can we event portable between Windows and Linux.
2) Use some library - this solution can be (but doesnt have to be) portable.


So:
If you want to use the firtst option you shell study function socket, bind, listen and accept. These functions aree usually called by a TCP server in order to start waiting and accepting connections. You will find pretty good examples how to use these function in the links above as well. BUT, be aware that HTTP protocol is a text protocol, and so you will have to parse and all possible HTTP-request and send all possible HTTP-responses in your code. And THAT will be really tedious to write !!!

Perhaps I would recommend to use some prepared library or API. If you are going to writ the server app for Windows, you might use WinInet API.

However, dont forget to make your server multithreaded, so that it can serve many client requests/connections at one time. This would require to create a thread for each incoming client connection. This thread would serve the client and then termionate. This is quite a difficult topic, if you are a beginer, but if you want to read about it, you can find some info good in MSDN documentation.

Best Regards,
J. K.


这篇关于关于使用c ++的websocket服务器实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆