I told DS (aged 4):
If they hit you once, shout at them good and proper so that you scare them off.
If they hit you again, hit them back, just once.
I was never the hitting type and even now as I am approaching 40 I am still trying to teach myself to stand up for myself. DH thinks hitting is wrong no matter what the situation, but I think there are circumstances when it's clearly not ideal but is a useful way to stop a potential bully and teach a child that standing up for themselves is important.
What do the rest of you do?