我正在使用iOS中的Asyncsocket客户端。
https://github.com/robbiehanson/CocoaAsyncSocket
如何知道服务器和客户端之间的套接字连接何时中断?
我应该使用什么委托方法来检测断开连接?
感谢。
答案 0 :(得分:2)
您应该阅读AsyncSocket.h,以下内容非常靠近顶部(第一个回调实际上会为您提供有关断开连接原因的信息,这可能很有用)
/**
* In the event of an error, the socket is closed.
* You may call "unreadData" during this call-back to get the last bit of data off the socket.
* When connecting, this delegate method may be called
* before"onSocket:didAcceptNewSocket:" or "onSocket:didConnectToHost:".
**/
- (void)onSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err;
/**
* Called when a socket disconnects with or without error. If you want to release a socket after it disconnects,
* do so here. It is not safe to do that during "onSocket:willDisconnectWithError:".
*
* If you call the disconnect method, and the socket wasn't already disconnected,
* this delegate method will be called before the disconnect method returns.
**/
- (void)onSocketDidDisconnect:(AsyncSocket *)sock;
答案 1 :(得分:1)
您似乎使用委托方法:
- (void)onSocketDidDisconnect:(AsyncSocket *)sock;