NEW BRUNSWICK, N.J. — A former Rutgers University student sent a message to a friend about wanting to “keep the gays away” and urged her to watch a feed from a webcam that he had trained on a bed where he expected his roommate to have a tryst with another man, according to text messages shown in court on Monday.

“Do it,” the former student, Dharun Ravi, told his friend Michelle Huang in a message on Sept. 21, 2010. “I have it pointed at his bed and the monitor is off so he can’t see you.”

The next day, the roommate, Tyler Clementi, jumped to his death from the George Washington Bridge. Mr. Ravi is now on trial on charges including invasion of privacy and bias intimidation, accused of spying on Mr. Clementi as he had sexual encounters with another man. Mr. Ravi is not charged with causing Mr. Clementi’s death.

Mr. Ravi said in a text message to Ms. Huang, whom he had known since high school, that through his webcam he had seen Mr. Clementi being intimate with a man he described as “older and creepy and definitely from the Internet.”