SRWebsocket close the connection ios

1.8k Views Asked by At

I am using SRWebsocket in my connection class I am trying to disconnect the socket when the app goes to background i have tried these things

SRWebSocket *_webSocket;


-(void)close

{


    [_webSocket close];
    _webSocket.delegate = nil;
    _webSocket = nil;


}

but it is not closing the socket please help me in doing so .

1

There are 1 best solutions below

0
On BEST ANSWER

Keep in mind that, if you nil the websocket delegate at this point, when the socket actually closes (it's not inmediate), there will be no delegate to process the webSocket:diCloseWithCode: event. But the socket should certainly be closed anyway.

It may not be that, but it would make more sense to just send the close message. Then wait for the didClose and there, you can nil both the delegate and the actual _websocket.