TODO: 1. detect socket close 2. add database support 3.