[英]Is it possible to stream data from client to server via http?
I'm wanting to stream data from a client (desktop or mobile) to a hosted server. 我想将数据从客户端(台式机或移动设备)流式传输到托管服务器。 It's not a large amount of data, 1 byte every 1/10 second - but the data needs to be streamed immediately (no buffering) and the connection needs to stay active for a long period of time (say 10 minutes max). 它不是大量数据,每1/10秒1个字节-但是数据需要立即进行流传输(不进行缓冲),并且连接需要长时间保持活动状态(例如最多10分钟)。
Because the server is hosted, I don't have the ability to use sockets - just http. 由于服务器是托管服务器,因此我无法使用套接字-只能使用http。
I know on the server side, if I was connecting to a client I can do this using persistent connections and just writing to the response stream. 我知道在服务器端,如果我要连接到客户端,则可以使用持久连接并仅写入响应流来执行此操作。
But is there a way to do this in reverse, where a client has a persistent connection to the server and is writing to the request stream? 但是,如果客户端与服务器保持持久连接并正在写入请求流,是否有相反的方法呢?
Clarification: I don't have to have this client->server communication done as persistent http connection, I was just wondering if it was possible, just so I could have symmetry with my planned server->client persistent http connection. 澄清:我不必将客户端->服务器通信作为持久性HTTP连接进行,我只是想知道是否可能,这样我就可以与计划中的服务器->客户端持久性HTTP连接保持对称。
From what I'm hearing, it sounds like I should just be able to do individual http posts and achieve the same or similar latency. 从我听到的消息看来,我应该只能够执行单个http帖子并实现相同或相似的延迟。
I'll go ahead and provide the answer to my own question, which seems to be: 我将继续回答我自己的问题,答案似乎是:
It's technically possible to do a persistent http connection from client->server, but nobody's implemented it yet because using the normal method of creating individual http requests seems to be fast enough for everybody's purposes. 从客户端到服务器建立持久的http连接在技术上是可行的 ,但是至今还没有人实现,因为使用正常的方法创建单个http请求似乎对于每个人的目的来说都是足够快的。
So that's what I ended up doing, simply using WebRequest.Create and the HttpWebRequest class and trusting that the framework is handling KeepAlive. 这就是我最终要做的事情,仅使用WebRequest.Create和HttpWebRequest类并相信该框架正在处理KeepAlive。 And in my prototypes that seems to be fast enough, although real-world performance remains to be seen. 在我的原型中,这似乎足够快,尽管实际性能仍有待观察。
AFAIK, streaming doesn't work when WCF is hosted in IIS. AFAIK,当WCF托管在IIS中时,流式传输不起作用。
I found this CodeProject article that says it's fixed in WCF 4.5. 我发现这篇CodeProject文章说它在WCF 4.5中已修复。
Can you get the client to make new calls every 1/10 sec? 您能否让客户每1/10秒拨打一次新电话? The TCP connection should be held open if you're using HTTP 1.1. 如果您使用的是HTTP 1.1,则TCP连接应保持打开状态。
我不确定这是否是一个好用例,但是SignalR可能适合您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.