SRWebSocketDelegate
The SRWebSocketDelegate protocol defines methods that allow you to manage the WebSocket lifecycle and handle incoming data.
Connection Events
webSocketDidOpen:
- (void)webSocketDidOpen:(SRWebSocket *)webSocket;
Called when the connection is successfully established and the handshake is complete.
webSocket:didFailWithError:
- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;
Called when the connection fails (e.g., timeout, network error, handshake failure).
webSocket:didCloseWithCode:reason:wasClean:
- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(nullable NSString *)reason wasClean:(BOOL)wasClean;
Called when the connection is closed. wasClean indicates if the server completed the close handshake.
Message Events
webSocket:didReceiveMessage:
- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message;
Called when a message is received. message will be an NSString for text frames or NSData for binary frames.
webSocket:didReceiveMessageWithString:
- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessageWithString:(NSString *)string;
Specific callback for text frames.
webSocket:didReceiveMessageWithData:
- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessageWithData:(NSData *)data;
Specific callback for binary frames.
Ping / Pong
webSocket:didReceivePong:
- (void)webSocket:(SRWebSocket *)webSocket didReceivePong:(nullable NSData *)pongData;
Called when the server responds to a Ping frame sent by the client.