Web 服务器的实现

发布于 2024-09-12 04:01:58 字数 1539 浏览 1 评论 0原文

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

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

发布评论

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

评论(5

一紙繁鸢 2024-09-19 04:01:58

如果您将此作为练习,我建议您使用事件驱动模型。

我认为没有关于这个主题的教程,因为所需的知识范围非常广泛 - HTTP 协议、文件访问、线程和并发、配置文件管理、套接字通信、日志记录、错误处理、MIME 类型......是的,即使只是共享静态资源,它仍然是一个大问题。

阅读一下,祝你好运!

If you're doing this as an exercise, I'd recommend an event-driven model.

I don't think there's one tutorial on this topic because the knowledge required is so far-ranging - the HTTP protocol, file access, threading and concurrency, configuration-file management, socket communication, logging, error handling, MIME types... Yeah, even just sharing static resources, it's still a biggie.

Read up, and good luck!

云醉月微眠 2024-09-19 04:01:58

我建议您熟悉 HTTP 请求格式 http://datatracker.ietf.org/doc/rfc2616/ 。从头开始实现 HTTP 并不是一件小事,但这无疑是一个很好的学习练习。

在 Java 本身中,为了简单起见,我建议使用每个请求一个线程的服务器 - http://tutorials.jenkov.com/java-multithreaded-servers/multithreaded-server.html - 使用 java.nio 提供文件。在并发设置中,java.nio 优于 java.io,因为它可以更好地平衡负载。您可能会发现基准表明 java.io 更快,但那是针对顺序单线程代码的。

I recommend familiarizing yourself with the HTTP request format http://datatracker.ietf.org/doc/rfc2616/. Implementing HTTP from scratch is no small feat, but it is certainly a good learning exercise.

Within Java itself for simplicity I recommend using a thread-per-request server - http://tutorials.jenkov.com/java-multithreaded-servers/multithreaded-server.html - that using java.nio for serving files. In a concurrent setting java.nio is preferable to java.io because it balances load better. You will likely find benchmarks that suggest that java.io is faster, but that is for sequential single-threaded code.

骷髅 2024-09-19 04:01:58

您可能会发现 ACME Web 服务器作为起点很有趣。我们用它来进行临时文件传输。当您熟悉它后,您可以看看是否可以发现它的瓶颈,然后思考如何修复它:)

http://acme.com/java/software/Acme.Serve.Serve.html

You might find the ACME web server interesting as a starting point. We use it for ad-hoc file transfers. When you have familarized yourself with it, you can see if you can discover its bottlenecks and then ponder on how to fix it :)

http://acme.com/java/software/Acme.Serve.Serve.html

牛↙奶布丁 2024-09-19 04:01:58

我建议 Apache MINA 来完成这项工作。它允许您指定编码器/解码器来正确处理 HTT 协议,并在请求到达时调用方法等。它在内部处理线程管理。没有它我永远不会开始一个网络项目。

I would suggest Apache MINA to do the job. It lets you specify Encoders/Decoders to deal with the HTT Protocol properly and calls a method when a request arrives etc. It handles thread management internally. I never start a networking project without it.

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