Solved issue of infinite loop with N=1 by adding an else condition at server to handle the case if it is receiving the same packet. Also made timeout as 0.3 based on the RTT values received from pings.