Refactor socket to keep long connetion and can receive cmd from client. Bug fixing.