Add close socket on connection ended prematurely and changed makefile