HTML 转发

发布于 2024-10-31 17:21:08 字数 530 浏览 2 评论 0原文

所以我一直在用 C++ 尝试一些简单的 HTML 转发。还没有取得太多成就,我对骨干有一些疑问。

第一:除了套接字库之外,我是否需要使用任何特殊的库来简单地转发 HTML 数据和连接?

第二:当客户端连接到 HTML 服务器时,TCP 连接是否保持打开状态?还是一旦发送数据就关闭?

第三:当我将数据从客户端转发到服务器时,数据包包含目标地址。从技术上讲,我应该能够读取这个地址并通过端口 80 连接到服务器,保持其打开,并在新打开的端口上发送和接收,对吗?有什么我必须做的吗?有时间限制吗?如果我直接在客户端和服务器之间直接转发每个数据包,网站应该在客户端上正确显示,对吗?

我宁愿将任何外部库保持在最低限度。但如果有必要,我可以扩展该程序以包含任何所需的库。

到目前为止,我已经从双方获取了数据,但是该网站无法运行。

[platform] :: windows.primary && posix_company.secondary

So I've been playing around with some simple HTML forwarding with c++. Haven't accomplished much and I have some questions on the backbone.

First: Do I need to use any special libraries other than socket libraries to simply forward HTML data and connections?

Second: When a client connects to an HTML server, is the TCP connection kept open? Or is it closed once data is sent?

Third: When I forward data, from a client to the server, the packet includes the destination address. I should technically be able to read this address and connect to the server via port 80, keep it open, and send and receive on that newly opened port right? Is there anything I have to do? Any time constraints? If I directly forward every single packet directly between the client and server the website should show up correctly on the client, correct?

I would prefer to keep any external libs to a minimum. But if necessary I can expand the program to include any required libraries.

So far I've gotten data to and from both parties, however the website does not function.

[platform] :: windows.primary && posix_compliant.secondary

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫卆 2024-11-07 17:21:08

第一:不,您不需要其他特殊的库,但不使用任何可用的库在某种程度上会重新发明轮子。

第二:不,HTTP 是一种无连接协议。

第三:HTTP 会话以请求标头开始,在您的情况下,该标头听起来像 POST。一次 POST 可能需要多个包,在此期间连接保持打开状态。服务器很可能会让你超时。

即使您不打算使用 libCURL,您也可以查看它。 (其来源是 C 语言,相当单一,但很常用)。

First: No you do not need other special libraries but not using any that are available would to some extent be reinventing the wheel.

Second: No, HTTP is a connectionless protocol.

Third: An HTTP session begins with a request header, which in your case sounds like a POST. A POST may take more than one package, during which time the connection remains open. The server may well time you out.

You might look at libCURL even if you do not intend using it. (The source for that is in C, and is rather monolithic but it is commonly used).

南薇 2024-11-07 17:21:08

经过大量研究后,我在工作中得到的最大帮助是这个网站

这个也有很大帮助。

LibCURL 无疑是最佳选择。它有点过时了,所有内容都是用 C 编写的,但这比重做所有内容要容易得多..

引用第二个站点:
与大多数网络协议一样,HTTP 使用客户端-服务器模型:HTTP 客户端打开连接并向 HTTP 服务器发送请求消息;然后服务器返回一条响应消息,通常包含所请求的资源。发送响应后,服务器关闭连接(使HTTP成为无状态协议,即不维护事务之间的任何连接信息)。

After doing quite a bit of research, the greatest help I've had in my endeavors has been this website.

This one also helped quite a bit.

LibCURL is certainly the way to go. It's kind of dated, and everything is in C, but it's much easier than redoing everything..

quote from second site:
Like most network protocols, HTTP uses the client-server model: An HTTP client opens a connection and sends a request message to an HTTP server; the server then returns a response message, usually containing the resource that was requested. After delivering the response, the server closes the connection (making HTTP a stateless protocol, i.e. not maintaining any connection information between transactions).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文