Http服务器,什么时候发送数据?

发布于 2024-11-15 16:17:23 字数 2777 浏览 2 评论 0原文

我已经用 Java 构建了一个文件服务器,但我很难理解何时应该开始提供文件数据。正如您在下面看到的,这是两个不同的客户端请求。有些提供两个请求,我不确定何时应该开始提供数据以及何时应该“忽略”。

客户#1:

06-15 08:06:21.290: VERBOSE/HttpSession(9425): SESSION 1: STARTED
06-15 08:06:21.290: INFO/HttpSession(9425): CLIENT: 
06-15 08:06:21.290: INFO/HttpSession(9425): GET /stream HTTP/1.1
06-15 08:06:21.290: INFO/HttpSession(9425): Host: 127.0.0.1:37914
06-15 08:06:21.290: INFO/HttpSession(9425): User-Agent: (Linux)
06-15 08:06:21.290: INFO/HttpSession(9425): SERVER:
06-15 08:06:21.290: INFO/HttpSession(9425): HTTP/1.1 200 OK 
06-15 08:06:21.290: INFO/HttpSession(9425): Date: Wed, 15 Jun 2011 12:06:21 GMT
06-15 08:06:21.290: INFO/HttpSession(9425): Server: HTTP Server
06-15 08:06:21.290: INFO/HttpSession(9425): Last-Modified: Mon, 06 Aug 2009 01:02:23 GMT
06-15 08:06:21.290: INFO/HttpSession(9425): Accept-Ranges: none
06-15 08:06:21.290: INFO/HttpSession(9425): Content-Type: audio/mpeg 
06-15 08:06:21.290: INFO/HttpSession(9425): 
06-15 08:06:26.720: VERBOSE/HttpSession(9425): SESSION 2: STARTED
06-15 08:06:26.730: INFO/HttpSession(9425): CLIENT: 
06-15 08:06:26.730: INFO/HttpSession(9425): GET /stream HTTP/1.1
06-15 08:06:26.730: INFO/HttpSession(9425): Host: 127.0.0.1:37914
06-15 08:06:26.730: INFO/HttpSession(9425): Accept: */*
06-15 08:06:26.730: INFO/HttpSession(9425): SERVER:
06-15 08:06:26.730: INFO/HttpSession(9425): HTTP/1.1 200 OK 
06-15 08:06:26.730: INFO/HttpSession(9425): Date: Wed, 15 Jun 2011 12:06:26 GMT
06-15 08:06:26.730: INFO/HttpSession(9425): Server: HTTP Server
06-15 08:06:26.730: INFO/HttpSession(9425): Last-Modified: Mon, 06 Aug 2009 01:02:23 GMT
06-15 08:06:26.730: INFO/HttpSession(9425): Accept-Ranges: none
06-15 08:06:26.730: INFO/HttpSession(9425): Content-Type: audio/mpeg 
06-15 08:06:26.730: INFO/HttpSession(9425): 
06-15 08:06:26.730: VERBOSE/HttpSession(9425): SESSION 2: ENDED

客户#2:

06-15 05:03:58.079 I/HttpSession(18335): CLIENT: 
06-15 05:03:58.079 I/HttpSession(18335): GET /stream HTTP/1.1
06-15 05:03:58.079 I/HttpSession(18335): Host: 127.0.0.1
06-15 05:03:58.079 I/HttpSession(18335): Accept: */*
06-15 05:03:58.079 I/HttpSession(18335): Icy-MetaData:1
06-15 05:03:58.079 I/HttpSession(18335): User-Agent: QuickTime;NvMM HTTP Client v0.1
06-15 05:03:58.089 I/HttpSession(18335): SERVER:
06-15 05:03:58.089 I/HttpSession(18335): HTTP/1.1 200 OK 
06-15 05:03:58.089 I/HttpSession(18335): Date: Wed, 15 Jun 2011 09:03:58 GMT
06-15 05:03:58.089 I/HttpSession(18335): Server: HTTP Server
06-15 05:03:58.089 I/HttpSession(18335): Last-Modified: Mon, 06 Aug 2009 01:02:23 GMT
06-15 05:03:58.089 I/HttpSession(18335): Accept-Ranges: bytes
06-15 05:03:58.089 I/HttpSession(18335): Content-Type: audio/mpeg 

I have built a file server in Java and I'm having difficulties with understanding when I should start serving the file data. As you can see below are two different client requests. Some provide two request and I'm not sure when I should start serving the data and when I should "ignore".

Client #1:

06-15 08:06:21.290: VERBOSE/HttpSession(9425): SESSION 1: STARTED
06-15 08:06:21.290: INFO/HttpSession(9425): CLIENT: 
06-15 08:06:21.290: INFO/HttpSession(9425): GET /stream HTTP/1.1
06-15 08:06:21.290: INFO/HttpSession(9425): Host: 127.0.0.1:37914
06-15 08:06:21.290: INFO/HttpSession(9425): User-Agent: (Linux)
06-15 08:06:21.290: INFO/HttpSession(9425): SERVER:
06-15 08:06:21.290: INFO/HttpSession(9425): HTTP/1.1 200 OK 
06-15 08:06:21.290: INFO/HttpSession(9425): Date: Wed, 15 Jun 2011 12:06:21 GMT
06-15 08:06:21.290: INFO/HttpSession(9425): Server: HTTP Server
06-15 08:06:21.290: INFO/HttpSession(9425): Last-Modified: Mon, 06 Aug 2009 01:02:23 GMT
06-15 08:06:21.290: INFO/HttpSession(9425): Accept-Ranges: none
06-15 08:06:21.290: INFO/HttpSession(9425): Content-Type: audio/mpeg 
06-15 08:06:21.290: INFO/HttpSession(9425): 
06-15 08:06:26.720: VERBOSE/HttpSession(9425): SESSION 2: STARTED
06-15 08:06:26.730: INFO/HttpSession(9425): CLIENT: 
06-15 08:06:26.730: INFO/HttpSession(9425): GET /stream HTTP/1.1
06-15 08:06:26.730: INFO/HttpSession(9425): Host: 127.0.0.1:37914
06-15 08:06:26.730: INFO/HttpSession(9425): Accept: */*
06-15 08:06:26.730: INFO/HttpSession(9425): SERVER:
06-15 08:06:26.730: INFO/HttpSession(9425): HTTP/1.1 200 OK 
06-15 08:06:26.730: INFO/HttpSession(9425): Date: Wed, 15 Jun 2011 12:06:26 GMT
06-15 08:06:26.730: INFO/HttpSession(9425): Server: HTTP Server
06-15 08:06:26.730: INFO/HttpSession(9425): Last-Modified: Mon, 06 Aug 2009 01:02:23 GMT
06-15 08:06:26.730: INFO/HttpSession(9425): Accept-Ranges: none
06-15 08:06:26.730: INFO/HttpSession(9425): Content-Type: audio/mpeg 
06-15 08:06:26.730: INFO/HttpSession(9425): 
06-15 08:06:26.730: VERBOSE/HttpSession(9425): SESSION 2: ENDED

Client #2:

06-15 05:03:58.079 I/HttpSession(18335): CLIENT: 
06-15 05:03:58.079 I/HttpSession(18335): GET /stream HTTP/1.1
06-15 05:03:58.079 I/HttpSession(18335): Host: 127.0.0.1
06-15 05:03:58.079 I/HttpSession(18335): Accept: */*
06-15 05:03:58.079 I/HttpSession(18335): Icy-MetaData:1
06-15 05:03:58.079 I/HttpSession(18335): User-Agent: QuickTime;NvMM HTTP Client v0.1
06-15 05:03:58.089 I/HttpSession(18335): SERVER:
06-15 05:03:58.089 I/HttpSession(18335): HTTP/1.1 200 OK 
06-15 05:03:58.089 I/HttpSession(18335): Date: Wed, 15 Jun 2011 09:03:58 GMT
06-15 05:03:58.089 I/HttpSession(18335): Server: HTTP Server
06-15 05:03:58.089 I/HttpSession(18335): Last-Modified: Mon, 06 Aug 2009 01:02:23 GMT
06-15 05:03:58.089 I/HttpSession(18335): Accept-Ranges: bytes
06-15 05:03:58.089 I/HttpSession(18335): Content-Type: audio/mpeg 

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

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

发布评论

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

评论(1

表情可笑 2024-11-22 16:17:23

如果您尝试提供音频或视频,则客户端可能正在尝试利用 HTTP 的 Range 标头。 Range 标头允许诸如跳到音频/视频流中间、清理等功能。桌面浏览器通常会发出几个请求,一个请求用于发现是否支持 Range 标头,另一个请求用于实际开始流式传输内容。只要您的服务器可以处理客户端终止套接字连接,您就可以安全地为每个连接开始流式传输内容。

如果您有兴趣,可以看看 Brisket - 它是一个轻量级的、基于 Java 的支持 Range 标头的 HTTP 服务器。

If you're trying to serve audio or video it's likely that the client is trying to leverage HTTP's Range header. The Range header allows features like skipping to the middle of an audio/video stream, scrubbing, etc. Desktop browsers often issue a couple of requests, one to discover if the Range header is supported, and a further request to actually begin streaming content. As long as your server can handle the client terminating socket connections you're probably safe to start streaming content for each connection.

If you're interested you could take a look at Brisket - it's a lightweight, Java-based HTTP server with Range header support.

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