123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- //
- // WebSocketManager.h
- // Anchor
- //
- // Created by 翟玉磊 on 2019/3/26.
- // Copyright © 2019 翟玉磊. All rights reserved.
- //
- #import <Foundation/Foundation.h>
- #import "SRWebSocket.h"
- #define WebSocketManager_Shared [WebSocketManager sharedSocketManager]
- NS_ASSUME_NONNULL_BEGIN
- @protocol WebSocketManagerDelegate <NSObject>
- - (void)webSocketManagerDidReceiveMessageWithObject:(id)object;
- @end
- /**
- 连接回调 errCode:0 说明连接成功
- */
- typedef void (^IMConnectCompletionHandler)(int errCode, NSString *errMsg);
- /**
- 离开回调 errCode:0 说明离开成功
- */
- typedef void (^IMCloseCompletionHandler)(int errCode, NSString *errMsg);
- @interface WebSocketManager : NSObject
- @property (nonatomic, strong) SRWebSocket *webSocket;
- @property (nonatomic, readwrite, weak) id<WebSocketManagerDelegate> delegate;
- + (instancetype)sharedSocketManager;//单例
- /// 建立长连接
- - (void)connectServerWithUrl:(NSString *)url connectCompletionHandler:(IMConnectCompletionHandler)completionHandler;
- /// 关闭长连接
- - (void)SRWebSocketCloseCompletionHandler:(IMCloseCompletionHandler)completionHandler;
- /// 发送数据给服务器
- - (void)sendDataToServer:(id)data;
- //重新连接服务器
- - (void)reConnectServer;
- @end
- NS_ASSUME_NONNULL_END
|