close sockets before opening a new socket