我对生成html页面的服务器进行编码,以便用户可以在其浏览器中查看这些页面。
它具有onGetRequest事件,这是它的处理程序:
var req = e.Request;
var res = e.Response;
var path = req.RawUrl.Replace("%20", " ");
if (path == "/")
path += "index.html";
if (path.Contains("/../"))
{
res.StatusCode = (int)HttpStatusCode.Forbidden;
return;
}
var content = this.ServerToRun.GetFile(path); //getting file to read
if (content == null)
{
res.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
string extension = path.Substring(path.LastIndexOf('.'));
string auto_mime = PageControls.MimeTypeDeterminer.GetMimeTypeFor(extension);
if (string.IsNullOrEmpty(auto_mime))
{
if (extension.Length > 1)
res.ContentType = "application/" + extension.Substring(1);
else
res.ContentType = "application/unknown";
}
else
res.ContentType = auto_mime;
if (path.EndsWith(".html") || path.EndsWith(".htm"))
res.ContentEncoding = Encoding.UTF8;
res.WriteContent(content); //sending content to client
我不了解支持实时流需要做什么。例如,我可以录制来自麦克风的音频,因此文件将每秒增加其大小。
我可以在html代码中执行此操作:
<audio>
<source src = "live.wav" type = "audio/wav" />
</audio>
服务器将接收对该文件的查询,将其读取到最后,然后将其发送给客户端,但是在此之后,live.wav
将获得服务器不再发送给客户端的更多声音。
因此,我被困住了,实时流如何工作以及我需要做什么?
我已经为每个客户端打开了WebSocket,所以我可以调用一些脚本。
您应该使用Transfer-Encoding: Chunked
HTTP标头。此标头允许您以块的形式发送数据,而无需指定Content-Length,因此客户端将不会关闭套接字,直到服务器指示已发送了最后一个块为止。参见https://en.wikipedia.org/wiki/Chunked_transfer_encoding。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句