Bacci, I'm not sure that anyone knows how two objects 'know' about each other. Your question could equally apply to gravity - how does the moon 'know' the earth is here? And electricity - how does the cloud know it is full of charged electrons that need to travel to the earth through lightning to reduce their electrical potential? I guess the same applies to the strong and the weak nuclear forces as well.
Wikipedia says "these interactions can usually be described, in a set of calculational approximation methods known as perturbation theory, as being mediated by the exchange of gauge bosons between particles" but this is beyond me.
I suggest you do a physics degree to be able to answer all those questions, seriously!