Investigators found he had sent and received a large number of messages linked to sexually explicit websites—some of which were exchanged while he was on duty.