The correct way to prevent this is to have a firewall running on the
Internet Connection, which will block the intrusions.
You can use XP's built-in firewall, or a 3-rd party one.
Some people will suggest you simply shut down the Messenger Service
on your PC, and this will also stop the spam messages.
But it doesn't cure the underlying problem that you have an
insecure machine exposed to the Internet.