Socket now closes if trying to create a new connection or closing the window