Socket:ios
1>Socket又稱"套接字」程序員
2>網絡上的兩個程序經過一個雙向的通訊鏈接實現數據的交換,這個鏈接的一端稱爲一個socket。數據庫
UDP(用戶數據報協議)json
1.HTTP 底層就是經過socket創建鏈接通訊管道,實現數據傳輸緩存
2.HTTP是一個TCP的傳輸協議(方式),它是一個可靠,安全的協議安全
傳輸格式:假設:這是假設,實際http的格式不是這樣的。服務器
http1.1,content-type:multipart/form-data,content-length:188,body:username=zhangsan&password=123456微信
可擴展消息處理現場協議)是基於可擴展標記語言(XML)的協議,它用於即時消息(IM)以及在線現場探測。這個協議可能最終容許因特網用戶向因特網上的其餘任何人發送即時消息網絡
傳輸格式:架構
<from>zhangsan<from>
<to>lisi<to>
<body>一塊兒吃晚上</body>
{
「from」:」zhangsan」,
」to」:」lisi」,
」body」:」中午一塊兒吃飯」
}
即時通信 :即時通信,又稱實時通信
/* *registerSDKWithAppKey: 區別app的標識,開發者註冊及管理後臺 apnsCertName: iOS中推送證書名稱。製做與上傳推送證書 */ //環信的初始化 // [[EaseMob sharedInstance] registerSDKWithAppKey:@"vgios#hxchat" apnsCertName:@」」]; //環信的初始化 並隱藏日誌輸出 [[EaseMob sharedInstance] registerSDKWithAppKey:@"vgios#hxchat" apnsCertName:@"" otherConfig:@{kSDKConfigEnableConsoleLogger:@(NO)}];
環信登陸:
註冊:
[[EaseMob sharedInstance].chatManager asyncRegisterNewAccount:」vgios1」 password:」123456」 withCompletion:^(NSString *username, NSString *password, EMError *error) { NSLog(@"error:%@ username:%@ pwd:%@",error,username,password); } onQueue:nil];
自動登陸:
/*! @method @brief 將要發起自動重連操做時發送該回調 @discussion @result */ - (void)willAutoReconnect; /*! @method @brief 自動重連操做完成後的回調(成功的話,error爲nil,失敗的話,查看error的錯誤信息) @discussion @result */ - (void)didAutoReconnectFinishedWithError:(NSError *)error;
EMChatManagerBuddyDelegate:
環信消息發送的流程
1.先把記錄保存到Conversation表
2.接着發送網絡請求,API以下
[[EaseMob sharedInstance].chatManager asyncSendMessage:message progress:self prepare:^(EMMessage *message, EMError *error) { KSLog(@"prepare %@",message.messageBodies); } onQueue:nil completion:^(EMMessage *message, EMError *error) { KSLog(@"完成 %@",message.messageBodies); } onQueue:nil];
顯示聊天消息:
// 1.獲取全部歷史會話 NSArray *conversations = [[EaseMob sharedInstance].chatManager conversations]; // 2.若是內存中,沒有會話,從數據庫中加載 if (conversations.count == 0) { conversations = [[EaseMob sharedInstance].chatManager loadAllConversationsFromDatabaseWithAppend2Chat:YES]; }
設置消息爲已讀:
// 設置當前會話全部消息都爲已讀 [self.conversation markAllMessagesAsRead:YES]; // 設置某條消息爲已讀 [self.conversation markMessageWithId:<#(NSString *)#> asRead:<#(BOOL)#>]
準備工做:
// 開始錄音 [[EMCDDeviceManager sharedInstance] asyncStartRecordingWithFileName:fileName completion:^(NSError *error){ if (error) { KSLog( @"failure to start recording"); } }]; // 結束錄音 [[EMCDDeviceManager sharedInstance] asyncStopRecordingWithCompletion:^(NSString *recordPath, NSInteger aDuration, NSError *error) { KSLog(@"%@",recordPath); }];
發送錄音:
// 語音對象 EMChatVoice *voice = [[EMChatVoice alloc] initWithFile:filePath displayName:@"audio"]; // 消息體 EMVoiceMessageBody *body = [[EMVoiceMessageBody alloc] initWithChatObject:voice]; EMMessage *message = [[EMMessage alloc] initWithReceiver:self.buddy.username bodies:@[body]]; message.messageType = eMessageTypeChat;// 私聊 // 不加密 message.requireEncryption = NO;
播放錄音:
[[EMCDDeviceManager sharedInstance] asyncPlayingWithPath:filePath completion:^(NSError *error) { NSLog(@"播放完成%@",error); }];
[[EaseMob sharedInstance].chatManager asyncLogoffWithUnbindDeviceToken:YES completion:^(NSDictionary *info, EMError *error) { if (!error) {//退出成功 }else{//退出失敗; } } onQueue:nil];
是否使用過XMPP,XMPP的實現原理: