Which timeout shoud I set to solve my problem?

I uset getbale to search the port flow. Sometimes the result return 700 ports. Sometimes the result return 100 ports without any exception. My colleague said it was due to the lack of machine capability. Shoud I solve this problem by set the timeout option? I find that there are two way to set timeout.Which way should I set?What is the difference between these two settings?

1.CommunityTarget: target.setTimeout(5000);
2. DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping();
transport.setSocketTimeout(5000);

Use (1) to set the timeout.