typo fixed, check if socket is closed