TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

The Journey from WebSockets to HTTP Streams

66 点作者 owulveryck超过 1 年前

4 条评论

voidwtf超过 1 年前
I would advise anyone finding inspiration in this post against using a similar solution in the real world. While this may work in a local only environment, once you encounter the real world consisting of Cloudflare, DPI&#x2F;MITM proxies, load balancers, zscaler, etc... it would most likely fail to work in this manner.<p>Standards are at least somewhat supported among the former, often not even correctly. Any solution you choose I&#x27;d suggest implementing a fall-back to the most basic of http methods (standard get&#x2F;post and polling for instance). You&#x27;ll find all types of problems once you start encountering middleware that just absolutely thrashes your expectations of a well functioning internet.
评论 #38606299 未加载
评论 #38606378 未加载
评论 #38606294 未加载
MuffinFlavored超过 1 年前
Does &quot;HTTP streams&quot; mean &quot;Server-Sent Events&quot; here: <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;API&#x2F;Server-sent_events&#x2F;Using_server-sent_events" rel="nofollow noreferrer">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;API&#x2F;Server-sent...</a> ?<p>I don&#x27;t see it spelled out in the article.<p>Edit: yes I do.<p>&gt; Internet and ChatGPT gave it a name: Server Sent Events<p>Interesting callout: websockets can be &quot;two way&quot; (server -&gt; client, client -&gt; server). SSE, you just get one way (server -&gt; client) and you have to do your typical POST to achieve the other way (client -&gt; server)
评论 #38612077 未加载
freedomben超过 1 年前
This is a really great write-up!<p>On a side note, the Remarkable Tablet is such a cool and hackable device. It surprises me that the company doesn&#x27;t open source more of their client software to get help from the community, which I bet would do a large chunk of the work for them for free as it&#x27;s mutually beneficial. Particularly as the market they are in is highly competitive, that could be a great way to get a great featureset, lower costs, while also providing something of immense value to the open source community. They could even offer a third-party app store of some sort and become the de-facto standard platform for e-ink devices! The rest are so locked down that this would be a huge competitive advantage.
评论 #38604550 未加载
riverdweller超过 1 年前
This approach was what we had to use back in the late 90s. We called it &quot;iframe streaming&quot;, or &quot;forever iframe&quot; (and years later, as an industry term emerged, &quot;comet&quot;). It worked surprisingly well, except in cases where a client sat behind a greedily buffering proxy. We would send JavaScript statements that invoked callbacks on the client, rather than just JSON, as this avoided the need to parse data to determine which business logic to use on the client. This has the limitation of being &quot;non-cross domain&quot; (i.e. the web page containing the callback functions have to be served from the same domain as the infinite document).<p>To get around buffering proxies, we optionally allowed our clients to use a JSONP long polling approach instead, whereby the client would dynamically generate a form inside a hidden iframe, and POST a request for JSONP data (JSON delivered wrapped in a callback), and the server would return data as soon as any was available. The client would immediately repeat the process to request more data, an infinitum.<p>Eventually, the emergence of the XMLHTTPRequest object in IE (and subsequently in other browsers) allowed us to implement cleaner long-poll-style methods, holding the connection open until data was available (and automatically reconnecting on error). This was later enhanced with CORS for delivery of data from arbitrary domains. As support for detecting updates to an in-progress response became available (via XMLHTTPRequest&#x27;s &quot;progress&quot; event, which for a long time was horribly buggy in IE ) our payloads became infinite streams too (of JavaScript callback invocations). Early versions of approach also required us to reload the entire page from time to time, as IE&#x27;s underlying implementations of these browser objects appeared to have memory leaks (that we did not see in Firefox, for example).<p>When IE8 was released, we allowed clients to optionally use its XDomainRequest object to stream a response instead.<p>Years later, the much cleaner Server Sent Events (SSE) and WebSocket options became possible. Intermediate proxy support was initially troublesome however, and while both of these were our preferred choices from a performance and API perspective, it took several years before we could consider removing support for our earlier approaches. Even today, there are network environments where an infinite sequence of long polls is the only reliable option...<p>My preference today? The JavaScript fetch API for sending commands, with a simple ack as a response, and an async flow of events over a persistent SSE connection, that feed into a simple JS message bus (implemented using the browser&#x27;s native event API) for delivery to vanilla JavaScript web components. Simple, clean, and consistent.