title: Why does the UDP client port change on the UDP server
body: <p>I've been following a simple UDP server/client tutorial found <a href="http://www.binarytides.com/udp-socket-programming-in-winsock/" rel="nofollow noreferrer">here</a>, and I have a quick question about which port the client is connecting to the server.</p>
  
  <p>From just viewing the code, it seems quite obvious that the server and client are connecting via port 8888:</p>
  
  <p>Client.cpp</p>
  
  <pre><code>#define SERVER "127.0.0.1"  //ip address of udp server
  #define BUFLEN 512  //Max length of buffer
  #define PORT 8888   //The port on which to listen for incoming data
  </code></pre>
  
  <p>Server.cpp</p>
  
  <pre><code>#define BUFLEN 512  //Max length of buffer
  #define PORT 8888   //The port on which to listen for incoming data
  </code></pre>
  
  <p>However, when I actually run the server and the client, the server says the client connected port is always different:</p>
  
  <p>First run (Server Log):</p>
  
  <p><a href="https://i.stack.imgur.com/Osyrc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Osyrc.png" alt="Note how the port changes"></a>
  <em>Note how the port changes from 8888</em></p>
  
  <p>Second run (Server Log)</p>
  
  <p><a href="https://i.stack.imgur.com/jj0q1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jj0q1.png" alt="enter image description here"></a></p>
  
  <p><em>Note how the port changes again</em></p>
  
  <p>Why would the connected ports change from 8888?</p>