1.In your first code you created only one socket , so for that you got only one port.But in your second code you created some number of sockets ,because you run a loop till 20000.For the each iteration of the loop your program tried to created a socket . So you got the ports for the connected sockets .

2. To store the ip in char array you need 16 bits.
char addr[16];

3.You can not easily access the external site ip's .Because they would accept the the outside connection easily .Then used have firewall security.

Last edited by karthigayan; 6Mar2010 at 12:56..