2016-03-29 5 views
3

Я использую MZFayeClient (https://github.com/m1entus/MZFayeClient) используя встроенный WebSocket. Мне нужно реализовать длинный опрос. Как это сделать? Когда начать? Нет информации (или достаточной информации) о том, как это сделать, или если есть библиотека Faye с длинным опросом.С чего начать применять длинный опрос в Faye для iOS

ответ

5

Я не разработчик IOS, но один из моих проектов помог моей команде IOS для интеграции сервера Faye.

В моем приложении у нас уже есть faye-сервер, уже запущенный на платформе rails для отправки уведомлений, и мы решили отправить уведомление на устройство IOS с использованием того же самого faye-сервера.

команда IOS просто следуйте инструкциям: https://github.com/pcrawfor/FayeObjC

self.client = [[MZFayeClient alloc] initWithURL:[NSURL URLWithString:@"ws://198.128.0.1:9292/faye"]]; 

ws://198.128.0.1:9292/faye // this URL is same which is used on web-app. 

subscribeToChannel & другие методы такие же, как мы используем на веб-приложения.

Простая установка Faye для Rails-приложений.

How can I push to Faye Server from Rails Controller?

Это будет работать для меня, я надеюсь, что также будет для вас ..

извините за мой плохой английский;)

2

1.Server up and running:

sudo rackup faye.ru -E production -s thin для запуска сервера Faye

Thin web server (v1.6.4 codename Gob Bluth) Maximum connections set to 
1024 Listening on localhost:9292, CTRL+C to stop 

Проверьте сервер работает

curl http://localhost:9292/faye -d 'message={"channel":"/server", "data":"hello"}' 

отклика журнала

[{"channel":"/server","successful":true}] 

Сервер:

[Faye::RackAdapter] Received message via HTTP POST: 
"{\"channel\":\"/server\", \"data\":\"hello\"}" [Faye::Server] 
Processing messages: [{"channel":"/server","data":"hello"}] (local: 
false) [Faye::Server] Passing through incoming extensions: 
{"channel":"/server","data":"hello"} [Faye::Server] Handling message: 
{"channel":"/server","data":"hello"} (local: false) 
[Faye::Engine::Proxy] Publishing message 
{"channel":"/server","data":"hello"} [Faye::Server] Processing reply: 
{"channel":"/server","successful":true} [Faye::Server] Passing through 
outgoing extensions: {"channel":"/server","successful":true} 
[Faye::Server] Returning replies: 
[{"channel":"/server","successful":true}] [Faye::RackAdapter] HTTP 
response: "[{\"channel\":\"/server\",\"successful\":true}]" 

2. Работа с клиентом: Скачать MZFayeClient

cd FayeObjC-master/examples 
pod install 
open FayeObjC.xcworkspace 

MZViewController.m

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.client = [[MZFayeClient alloc] initWithURL:[NSURL URLWithString:@"http://localhost:9292/faye"]]; 
    [self.client subscribeToChannel:@"/server" success:^{ 
     NSLog(@"ok"); 
    } failure:^(NSError *error) { 
     NSLog(@"Server %@",error); 
    } receivedMessage:^(NSDictionary *message) { 
     NSLog(@"Server %@",message); 
    }]; 

    self.client.delegate = self; 
} 

3.Постройте пример: Нажмите на соединение:

[Faye::RackAdapter] Received message via WebSocket[hybi-13]: 
"{\"supportedConnectionTypes\":[\"long-polling\",\"callback-polling\",\"iframe\",\"websocket\"],\"channel\":\"\\/meta\\/handshake\",\"minimumVersion\":\"1.0beta\",\"version\":\"1.0\"}" 
[Faye::Server] Processing messages: 
[{"supportedConnectionTypes":["long-polling","callback-polling","iframe","websocket"],"channel":"/meta/handshake","minimumVersion":"1.0beta","version":"1.0"}] 
(local: false) [Faye::Server] Passing through incoming extensions: 
{"supportedConnectionTypes":["long-polling","callback-polling","iframe","websocket"],"channel":"/meta/handshake","minimumVersion":"1.0beta","version":"1.0"} 
[Faye::Server] Handling message: 
{"supportedConnectionTypes":["long-polling","callback-polling","iframe","websocket"],"channel":"/meta/handshake","minimumVersion":"1.0beta","version":"1.0"} 
(local: false) [Faye::Engine::Proxy] Created new client 
"f68nwz5foyf1brczhmutdhclhnbtth5" [Faye::Engine::Proxy] Ping 
"f68nwz5foyf1brczhmutdhclhnbtth5", 45 [Faye::Server] Processing reply: 
{"channel":"/meta/handshake","successful":true,"version":"1.0","supportedConnectionTypes":["long-polling","cross-origin-long-polling","callback-polling","websocket","eventsource","in-process"],"clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","advice":{"reconnect":"retry","interval":0,"timeout":45000}} 
[Faye::Server] Passing through outgoing extensions: 
{"channel":"/meta/handshake","successful":true,"version":"1.0","supportedConnectionTypes":["long-polling","cross-origin-long-polling","callback-polling","websocket","eventsource","in-process"],"clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","advice":{"reconnect":"retry","interval":0,"timeout":45000}} 
[Faye::Server] Returning replies: 
[{"channel":"/meta/handshake","successful":true,"version":"1.0","supportedConnectionTypes":["long-polling","cross-origin-long-polling","callback-polling","websocket","eventsource","in-process"],"clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","advice":{"reconnect":"retry","interval":0,"timeout":45000}}] 
[Faye::RackAdapter] Received message via WebSocket[hybi-13]: 
"{\"channel\":\"\\/meta\\/connect\",\"clientId\":\"f68nwz5foyf1brczhmutdhclhnbtth5\",\"connectionType\":\"websocket\"}" 
[Faye::Server] Processing messages: 
[{"channel":"/meta/connect","clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","connectionType":"websocket"}] 
(local: false) [Faye::Server] Passing through incoming extensions: 
{"channel":"/meta/connect","clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","connectionType":"websocket"} 
[Faye::Server] Handling message: 
{"channel":"/meta/connect","clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","connectionType":"websocket"} 
(local: false) [Faye::Engine::Proxy] Accepting connection from 
"f68nwz5foyf1brczhmutdhclhnbtth5" [Faye::Engine::Proxy] Ping 
"f68nwz5foyf1brczhmutdhclhnbtth5", 45 [Faye::RackAdapter] Received 
message via WebSocket[hybi-13]: 
"{\"channel\":\"\\/meta\\/subscribe\",\"clientId\":\"f68nwz5foyf1brczhmutdhclhnbtth5\",\"subscription\":\"\\/server\"}" 
[Faye::Server] Processing messages: 
[{"channel":"/meta/subscribe","clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","subscription":"/server"}] 
(local: false) [Faye::Server] Passing through incoming extensions: 
{"channel":"/meta/subscribe","clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","subscription":"/server"} 
[Faye::Server] Handling message: 
{"channel":"/meta/subscribe","clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","subscription":"/server"} 
(local: false) [Faye::Engine::Proxy] Subscribed client 
"f68nwz5foyf1brczhmutdhclhnbtth5" to channel "/server" [Faye::Server] 
Processing reply: 
{"clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","channel":"/meta/subscribe","successful":true,"subscription":"/server"} 
[Faye::Server] Passing through outgoing extensions: 
{"clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","channel":"/meta/subscribe","successful":true,"subscription":"/server"} 
[Faye::Server] Returning replies: 
[{"clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","channel":"/meta/subscribe","successful":true,"subscription":"/server"}] 

Тип "привет", а затем отправить

[Faye::RackAdapter] Received message via WebSocket[hybi-13]: 
"{\"data\":{\"text\":\"hello\"},\"clientId\":\"f68nwz5foyf1brczhmutdhclhnbtth5\",\"channel\":\"\\/browser\",\"id\":\"MQ==\"}" 
[Faye::Server] Processing messages: 
[{"data":{"text":"hello"},"clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","channel":"/browser","id":"MQ=="}] 
(local: false) 
[Faye::Server] Passing through incoming extensions: 
{"data":{"text":"hello"},"clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","channel":"/browser","id":"MQ=="} 
[Faye::Server] Handling message: 
{"data":{"text":"hello"},"clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","channel":"/browser","id":"MQ=="} 
(local: false) 
[Faye::Engine::Proxy] Publishing message 
{"data":{"text":"hello"},"clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","channel":"/browser","id":"MQ=="} 
[Faye::Server] Processing reply: 
{"id":"MQ==","clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","channel":"/browser","successful":true} 
[Faye::Server] Passing through outgoing extensions: 
{"id":"MQ==","clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","channel":"/browser","successful":true} 
[Faye::Server] Returning replies: 
[{"id":"MQ==","clientId":"f68nwz5foyf1brczhmutdhclhnbtth5","channel":"/browser","successful":true}] 

Надежда эта помощь.

 Смежные вопросы

  • Нет связанных вопросов^_^