ios - Using CocoaHTTPServer to "send" a message -


i using cocoahttpserver in macosx app (server) serves local directory of images. have corresponding ios app (client) uses afhttprequestoperation (afnetworking) retrieve image file mac on local network. working well.

what next is, when user chooses specific image in mac app ipad app notified download image , display it.

the method employ serve simple imagetodisplay.txt file includes file name of image display. ipad app polling file, , if filename changes downloads it, etc. works seems clunky. have thought of implementing method on server return filename. approach still require polling client.

is there more elegant way trigger download (without polling) pieces have in place? essentially sending message server client - "download image27.jpg now"

websockets (socketrocket)

there few ways implement this. noted in comments, websockets one. robust freely available websockets library ios socketrocket (which rhymes). there ample sample (also rhymes) code on page linked to, won't include here.

afnetworking

since you're using afnetworking already, take @ new afnetworking 2.0 (to released soon), includes support realtime networking via rocket.

this allow app maintain open connection, , this:

[client subscribe:@"/currentimage" usingblock:^(nsarray *operations, nserror *error) {     (afjsonpatchoperation *operation in operations) {         switch (operation.type) {             case afjsonreplaceoperationtype:                 // replace old image new image                 break;             default:                 break;         }     } } error:nil]; 

as long client doesn't cancel, continue receive updates server whenever happen.

your server need send data in appropriate format, , there's experimental branch of rack::scaffold this.

notes

these approaches might overkill if you're changing image once week; in case should cache image reasonable time period.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -