How to check in which state is a socket ?