adjust the code construction and add the exception catch of client close