The primary purpose of layer 4 port assignment is to identify the processes or services that are communicating within the end devices. While the first 3 layers are physical, data link and network layers the 4th layer is a transport layer. The transport layer functions to provide end-to-end communication services for applications.
The two main protocols at the transport layer are TCP and UDP. These connections using either TCP or UDP are done from port to port. Each device ends up having different gateways where communication is able to go in or out. Layer 4 is integral in a successful network.