幸运飞艇停吗

ASP源碼.NET源碼PHP源碼JSP源碼JAVA源碼DELPHI源碼PB源碼VC源碼VB源碼Android源碼
當前位置:首頁 >> 網絡編程 >> IOS開發 >> iOS WebSocket長鏈接

iOS WebSocket長鏈接(1/2)

來源:網絡整理     時間:2018-11-01     關鍵詞:

BENPIANWENZHANGZHUYAOJIESHAOLE" iOS WebSocketCHANGLIANJIE",ZHUYAOSHEJIDAOFANGMIANDENEIRONG,DUIYUIOSKAIFAGANXINGQUDETONGXUEKEYICANKAOYIXIA: WebSocketWebSocket SHI HTML5 YIZHONGXINDEXIEYI。TASHIXIANLELIULANQIYUFUWUQIQUANSHUANGGONGTONGXIN,NENGGENGHAODEJIESHENGFUWUQIZIYUANHEDAIKUANBINGDADAOSHISHITONGXUN,TAJIANLIZAI TC...

WebSocket

WebSocket SHI HTML5 YIZHONGXINDEXIEYI。TASHIXIANLELIULANQIYUFUWUQIQUANSHUANGGONGTONGXIN,NENGGENGHAODEJIESHENGFUWUQIZIYUANHEDAIKUANBINGDADAOSHISHITONGXUN,TAJIANLIZAI TCP ZHISHANG,TONG HTTP YIYANGTONGGUO TCP LAICHUANSHUSHUJU,DANSHITAHE HTTP ZUIDABUTONGSHI:WebSocket SHIYIZHONGSHUANGXIANGTONGXINXIEYI.

YOUYUXIANGMUXUYAOCHUANGJIANYIGELIAOTIANSHI,XUYAOTONGGUOCHANGLIANJIE,HEHOUTAIBAOCHITONGXUN,JINXINGLIAOTIAN,BINGQIESHISHIJINXINGREDIANXIAOXIDETUISONG.

幸运飞艇停吗MUQIANFacebookDESocketRocketYINGGAISHIMUQIANZUIHAODEGUANYUSocketRocketSHIYONGDEKUANGJIALE.ERQIEJIANDANYIYONG.

使用

YIBANYIGEXIANGMUZAIQIDONGHOUDEMOUGESHIJIHUIQIDONGCHUANGJIANYIGECHANGLIANJIE,RUGUOXUYAODUOGEJIUDUOCICHUANGJIAN.RUGUOZHIYAOYIGEJIUKEYIFENGZHUANGWEIYIGEDANLI,QUANJUSHIYONG.

KEYISHIYONGpodpodGUANLIKU, ZAIpodfileZHONGJIARU

pod 'SocketRocket'

幸运飞艇停吗ZAISHIYONGMINGLINGXINGGONGJUcdDAODANGQIANGONGCHENG ANZHUANG

pod install

幸运飞艇停吗DAORUTOUWENJIANHOUJIKESHIYONG.

幸运飞艇停吗WEIQIUWENDING,WODEZUOFASHIcopyDEFaceBookLISocketRocketKUDAOXIANGMULI. -->SocketRocketDIZHI

1.首先創建一個名為WebSocketManager的單例類,

+(instancetype)shared;

2.CHUANGJIANYIGEMEIJU,FENBIEBIAOSHIWebSocketDELIANJIEZHUANGTAI

typedef NS_ENUM(NSUInteger,WebSocketConnectType){
    WebSocketDefault = 0,   //初始狀態,未連接,不需要重新連接
    WebSocketConnect,       //已連接
    WebSocketDisconnect    //連接后斷開,需要重新連接
};

3.CHUANGJIANLIANJIE

//建立長連接
- (void)connectServer;

4.CHULILIANJIECHENGGONGDEJIEGUO;

-(void)webSocketDidOpen:(RMWebSocket *)webSocket; //連接成功回調

5.CHULILIANJIESHIBAIDEJIEGUO

- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;//連接失敗回調

6.JIESHOUXIAOXI

///接收消息回調,需要提前和后臺約定好消息格式.
- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessageWithString:(nonnull NSString *)string

7.GUANBILIANJIE

- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;///關閉連接回調的代理

幸运飞艇停吗8.WEIBAOCHICHANGLIANJIEDELIANJIEZHUANGTAI,XUYAODINGSHIXIANGHOUTAIFASONGXIAOXI,JIUSHISUCHENGDE:XINTIAOBAO.

XUYAOCHUANGJIANYIGEDINGSHIQI,GUDINGSHIJIANFASONGXIAOXI.

9.LIANJIEDUANKAIQINGKUANGCHULI:

SHOUXIANPANDUANSHIFOUSHIZHUDONGDUANKAI,RUGUOSHIZHUDONGDUANKAIJIUBUZUOCHULI.

RUGUOBUSHIZHUDONGDUANKAILIANJIE,XUYAOZUOZHONGXINLIANJIEDELUOJI.

JUTIDAIMARUXIA:

WebSocketManager.h 中的代碼

上一篇模仿微信朋友圈視頻播放 下一篇:沒有了

相關圖片

相關文章