title: How does port numbering works for receiving MODBUS TCP packets?
body: <p>I am running an application on my microcontroller(MSP432), which writes data to an Ethernet cable to send it over to PC.</p>
  
  <p>I am using Packet sender to view the data received on the port(502) on PC from MC.
  <a href="https://i.stack.imgur.com/lzMYl.jpg" rel="nofollow noreferrer">Data received on PC</a></p>
  
  <p>As we can see in the above picture, the port numbers of MC are increment for every packet sent. 
  What will happen when it reaches to the maximum number? 
  Will it restart at some other port number and proceed with the process or will it stop? </p>
  
  <p>Edit1: Modbus protocol library used from <a href="http://myarduinoprojects.com/modbus.html" rel="nofollow noreferrer">http://myarduinoprojects.com/modbus.html</a></p>
  
  <p>Edit2: 
  Making a call to this function everytime i have a new data to send through MODBUS.    <strong>Mb.Req(MB_FC_WRITE_MULTIPLE_REGISTERS, 0,11,0);</strong></p>
  
  <pre><code> if (MbmClient.connect(ServerIp,502)) {
    digitalWrite(GREEN_LED, HIGH);
  #if DEBUG
    //Serial.println("connected with modbus slave");
   // Serial.print("Master : ");
    for(int i=0;i&lt;MbmByteArray[5]+6;i++) {
      if(MbmByteArray[i] &lt; 16){
      //Serial.print("0");
    }
      //Serial.print(MbmByteArray[i],HEX);
      if (i != MbmByteArray[5]+5) {
      //Serial.print(".");
    } else {
    //Serial.println();
    }
    }
  #endif    
  MbmClient.write(MbmByteArray,13+(Count*2));
  
  MbmCounter = 0;
  MbmByteArray[7] = 0;
  MbmPos = Pos;
  MbmBitCount = Count;
  
  *state= true;
  MbmClient.stop();
  delay(100);
  digitalWrite(GREEN_LED, LOW);   
  } else {  
  
    *state= false;
    MbmClient.stop();
  }
  </code></pre>