i understand how to create a socket and assign a port to a socket. But how can i make a for loop to auto assign 21 ports to it? need some helps!!!

You don't. One socket, one port. On the server side you can reserve a block of ports for use by the server's clients in the hosts file. The location of that file depends on the operating system. On my computer running Vista its located here:

ok if i i wans to cretate 21 sockects wif 21 ports as all these 21 ports are for different thing! Instead of creating 21 hard coded sockects, i would like to make a for loop to auto create it

I would add the ports you want to use in the hosts file, then your program can read the host file to find out what ports to use.

thanks Ancient Dragon for ur help and info!!! i got wat u mean!!! thanks again!!! :)