How can I avoid, to send data via CFSocketSendData to an invalid socket?
I’ve try to determine the socket state with CFSockerIsValid, but this method
returns still true when the other side is close.
How can I determine if the socket is valid? In order so avoid Errors.
If the other side closes the socket, your callback (which you specified in CFSocketCreate) will get invoked with a callback type of kCFSocketDataCallBack, yet the data will be empty. Test for it like this:
You can set a flag there and use that to know that your connection is dropped, and then when you go to write to a dropped connection, attempt to reconnect or notify the user or whatever you want to do.