Fixed the Socket error at close
Added online check