Server finish

Code by Nhu Quang
Edit, convert to c++ by Ngoc Thanh