title: How can I benchmark TCP and UDP using C?
body: <p>I want to measure <strong>message latency</strong> and <strong>throughput</strong> for <strong>both</strong> TCP and UDP using C sockets. I am writing a client.c and server.c (Question 1: Do I have to?) that run on different servers to accomplish this. I have to take several measurements using different packet sizes and multiple trials and plot my results.</p>
  
  <p>For message latency:
  Send a packet of varying size and measure the round trip time and divide by 2 to get latency.
  Question 2: I send a packet of size x, and then from server.c I send the packet back. So at the client I start the timer, send packet and then wait till I receive the packet then stop the timer. The timer/2 is my latency? <em>What are the steps to go about measuring this?</em></p>
  
  <p>For throughput:
  Question 3: How would I measure throughput of both? <em>What are the steps to go about doing this?</em></p>
  
  <p>Im a beginner to Unix socket programming in C so detail would be helpful, with emphasis on the bechnmarking aspect.</p>
  
  <p>EDIT: I cannot use tools that already exist. I need to write my own.</p>
  
  <p>Thanks!</p>