“网络浏览器”程序可以在 Windows 中运行,但不能在 Linux 中运行

发布于 2024-10-17 13:17:19 字数 452 浏览 3 评论 0原文

我不会发布我的代码,它是用于学校项目的,我不想冒我的代码被复制的风险。话虽这么说,我不期望得到具体的答案,但任何想法将不胜感激。

无论如何,我的任务如下:我应该在终端中模拟网络浏览器。用户提供IP地址、文件路径和端口号。然后,我必须创建获取请求,将其发送到服务器并从响应中解析文件的内容长度。最后,我将使用内容长度来计算在文件中读取的字节数,以便我知道读取何时完成。所有这些数据都将写入 html 文件。

奇怪的是我开始在我的家用机器(Linux)上处理这个问题,并且能够解析内容长度和队列到 html 文件的开头并开始阅读。每次读取后,我都会从内容长度中减去读取的字节数,当我清零时,我还没有读取整个文件。但是,如果我在其中一台学校机器(使用 cygwin 的 Windows)上运行它,它会读取整个文件。

我已经使用打印语句进行了调试,并确认我正确解析了内容长度并且倒计时也正常工作。这让我摸不着头脑。有什么想法吗?

谢谢

I am not going to post my code, it is for a school project and I don't want to risk having my code copied. That being said I don't expect an concrete answer but any thoughts would be appreciated.

Anyway, my assignment was as follows: I am suppose to simulate a web browser in the terminal. The user provides an IP address, file path and port number. I then have to create the get request send it to the server and parse the file's content length from the response. Finally I am to use the content length to count the bytes as I read in the file so I know when the read is complete. All of this data is to be written to an html file.

The weird part is I started working on this on my home machine (Linux) and was able to parse the content length and queue to the beginning of the html file and start reading. After after each read I subtract the number of bytes I read from the content length and when I zero out I haven't read the entire file. However, if I run this on one of the school machines (Windows using cygwin) it reads the entire file.

I've debugged using print statments and confirmed that I am parsing the content length correctly and the countdown is working also. It has me scratching my head. Any ideas?

Thanks

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

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

发布评论

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

评论(2

月亮邮递员 2024-10-24 13:17:19

如何确定您没有阅读整个文件?你依赖EOF吗?如果是这样,您知道 HTTP/1.1 连接持久性吗?

How do you determine that you haven't read the entire file? Are you relying on EOF? If so are you aware of HTTP/1.1 connection persistence?

我也只是我 2024-10-24 13:17:19

您在 Windows 上使用的 stdio 库很可能会对数据中的任何 CR-LF 组合进行转换。检查编译器手册中的 open 函数并确保模式是二进制的。这是一个经典的移植问题,需要使用 ifdef 编译不同的代码。

检查您的 Windows 编译器是否支持像 WIN32 这样的常量,您可以像这样使用它

#if defined(WIN32)
   /* do this */
#else
   /* do that */
#endif

Chances are that the stdio library that you are using on Windows does translations on any CR-LF combinations in the data. Check your compiler's manual for the open function and make sure that the mode is binary. This is a classical porting problem which requires different code to be compiled using ifdefs.

Check if your Windows compiler supports a constant like WIN32 which you can use like this

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