How do network protocols like TCP and UDP impact application latency and reliability in a distributed system?