开发者

asyncsocket - best way to handle disconnects

开发者 https://www.devze.com 2023-04-05 01:59 出处:网络
I am using Asyncsocket for iPhone WIFI communication. Since [asyncsocket isconnected] does not seem to tell if the connection is still valid until the next read/write attempt starts, it is quite diffi

I am using Asyncsocket for iPhone WIFI communication. Since [asyncsocket isconnected] does not seem to tell if the connection is still valid until the next read/write attempt starts, it is quite difficult to restart new communication without "testing". And testing is quite complicated since the callback from the read has to know how to continue. In particular if there are couple of buttons which initiate different messages, the mechanism becomes kind of complicated.

What is the best way to handle such disconnects?

I have tried to use [asyncsocket isconnected] before sending the msg, but this will return only the last valid state, ie returns true even though in reality the connection is lost.

Also disconnecting followed by an immedia开发者_如何学Gote connect before each new msg gets send is difficult to handle, since it will not really disconnect until the next msg is being send, which again causes an error.

So I end up believing testing is the only - even though quite complicated - solution. Before I implement this (and hopefully it will work) I'd rather ask here...

Many thanks!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号