You can take the port number as a CLA. So for the server:
Code:
int portno = atoi(argv[1]); //use atoi to convert the 2nd CLA to an int. atoi means, ascii to integer.
Code:
serv_addr.sin_port = htons(portno); //serv_addr is a variable of the struct, sockaddr_in.
//sin port is a field inside of the struct of type unsigned short.
//you must use htonl(host to network long). Its converts host byte order to network byte order.
Now you can specify the portno on the command line as the 2nd arg.
Same applies to the client.