0
我正在使用iOS中的Asyncsocket客戶端。iOS中的Asyncsocket斷開連接事件
https://github.com/robbiehanson/CocoaAsyncSocket
我怎麼知道什麼時候服務器和客戶端之間的套接字連接壞了?
應使用什麼委託方法來檢測斷開?
謝謝。
我正在使用iOS中的Asyncsocket客戶端。iOS中的Asyncsocket斷開連接事件
https://github.com/robbiehanson/CocoaAsyncSocket
我怎麼知道什麼時候服務器和客戶端之間的套接字連接壞了?
應使用什麼委託方法來檢測斷開?
謝謝。
你應該閱讀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;
看來,您使用的委託方法:
- (void)onSocketDidDisconnect:(AsyncSocket *)sock;
非常感謝。 – user403015 2011-12-14 14:01:03