开发者

How to do HTTP Server Push -- aka do I NEED STOMP, AMPQ, etc?

开发者 https://www.devze.com 2022-12-08 09:32 出处:网络
I am writing a collection of web services, one of which needs to implement server push. The client will be native Objective-C. I want this to be as simple, fast, and lightweight as possible. The data

I am writing a collection of web services, one of which needs to implement server push.

The client will be native Objective-C. I want this to be as simple, fast, and lightweight as possible. The data transmitted will be JSON. Is it possible to开发者_Go百科 do this without using a message broker?


There's an HTTP technique called COMET in which the client spins up a thread that makes a potentially very long-lived request to the HTTP server. Whenever the server wants to send something to the client, it sends a response to this request. The client processes this response and immediately makes another long-lived request to the server. In this way the server can send information while other things happen in the client's main execution thread(s). The information sent by the serve can be in any format you like. (In fact, for clients in a web browser doing COMET with a Javascript library, JSON is perfect.)

@DevDevDev: It's true that COMET is most often associated with a Javascript-enabled browser, but I don't think it has to be. You might check out iStreamLight, which is an Objective-C client for the iPhone that connects to COMET servers. It's also discussed in this interview with the author.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号