implemented rules for udp, and tcp. TODO extensive testing and refactoring.