Implemented end() function, though a bug still remain: reconnection always
fails.