gpt4 book ai didi

iphone - iOS 中的 Asyncsocket 断开连接事件

转载 作者:行者123 更新时间:2023-11-28 20:41:14 24 4
gpt4 key购买 nike

我正在 iOS 中开发 Asyncsocket 客户端。

https://github.com/robbiehanson/CocoaAsyncSocket

我怎么知道服务器和客户端之间的套接字连接何时断开?

我应该使用什么委托(delegate)方法来检测断开连接?

谢谢。

最佳答案

您应该阅读 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;

关于iphone - iOS 中的 Asyncsocket 断开连接事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8505530/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com