char buf[4096]; data_size = recv(MainSocket, buf, 4096, 0); if (data_size > 0) { buf[data_size] = 0x00; } а если data_size вернет все 4096 ?