You can take the port number as a CLA. So for the server:
int portno = atoi(argv); //use atoi to convert the 2nd CLA to an int. atoi means, ascii to integer.
Now you can specify the portno on the command line as the 2nd arg.
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.
Same applies to the client.