When you send a message via a port, it is forwarded along all port connections outside the agent this port belongs to.
When a message is received at a port, it is forwarded to all connected statecharts and along all port connections inside the agent this port belongs to.
When a message arrives at a port, it is processed depending on the direction the message is going.
When a message arrives at a statechart, it is received by the statechart and the method receiveMessage() of the statechart is called.
The message routing rules are illustrated on the figure below: