简体   繁体   English

是否可以通过http将数据从客户端流传输到服务器?

[英]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. 在我的原型中,这似乎足够快,尽管实际性能仍有待观察。

Perhaps a WebSocket would be useful. 也许WebSocket是有用的。 It lets you create a "socket" over HTTP, so you can use it to send data from the client to the server over HTTP. 它使您可以通过HTTP创建“套接字”,因此可以使用它通过HTTP将数据从客户端发送到服务器。

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.

相关问题 在.Net控制台应用程序中将数据写入请求流期间,是否可以侦听HTTP服务器的响应? - Is it possible to listen response from HTTP server during writing data to request stream in .Net console app? 是否可以通过 HTTP 或 FTP 协议而不是 TCP/IP 传输数据 stream - Is it possible to transfer data stream via HTTP or FTP protocol instead of TCP/IP 从客户端到服务器以及从服务器到客户端的Http加密 - Http with Encryption from Client to Server and Server to Client 无法通过 WCF 从客户端向服务器发送流数据 - Can't send streamed data from client to server via WCF 如何制作 http 客户端,通过多部分表单数据发送 Base64 加密八位字节 stream? - How can I make a http client that sends Base64 encrypted octet stream via Multipart form data? 是否可以仅将信号器用于从服务器到客户端的数据接收? - Is it possible to use the signalr only for receiving data from server to Client? 是否可以将ReactJS服务器渲染与客户端发送的数据一起使用? - Is it possible to use ReactJS server rendering with data sent from the client? 是否可以从服务器连接客户端 - Is it possible to connect with client from server 是否可以通过Graph API从Facebook的Live Stream插件中获取数据? - Is it possible to get the data from Facebook's Live Stream plugin out via the Graph API? Web服务器:从流中读取http请求 - Web server: reading http request from stream
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM