use sock.shutdown() before sock.close()