当前位置: 首页 > 工具软件 > SocketRocket > 使用案例 >

SocketRocket实现即时通讯

程成天
2023-12-01

1.可在github上下载,包含了demo和测试地址

https://github.com/facebook/SocketRocket

2.遇到的BUG:

Connection Failed:Error Domain=SRWebSocketErrorDomain
 Code=2133 "Invalid Sec-WebSocket-Accept response." 
Sec-WebSocket-Accept response.}

解决方法:URL后面添加ws。

3.使用

    //初始化
    self.webSocket = [[SRWebSocket alloc] initWithURL:URL];
    self.webSocket.delegate = self;
    [self.webSocket open];

常用代理方法

 - (void)webSocketDidOpen:(SRWebSocket *)webSocket;
 - (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;
- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessageWithString:(NSString *)string;
- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:
(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;
 类似资料: