Client/Server Programming: Default argument for unknown service name?

I am writing a client server program that doesn't have a specific service name...
I am really only familiar with the "echo" and "time" service.  What should I have as
a default argument for the service if this is something I'm making myself?

void main(int argc, char *argv[])
      char      *service = argv[1];  //port number??????      
      char      *host ="localhost";  //IP address
      //arguments are entered in on the command line
      WSADATA      wsadata; //Creating a WSADATA object called wsadata
      switch (argc)
      case 1:      break;
            case 2: service = argv[1];
            case 3: service = argv[1];
                        host = argv[2];
            default: errexit("usage: TCPmusic[port]\n");

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

murugesandinsC C++ Shell script AIX CYGWIN_NT HP-UX Linux MINGW SunOSCommented:
The service mentioned here is not the port number. A port number represent an endpoint or a channel for network communications. Services are programs that provides you the services.

For example
ftp,telnet,smtp,nntp,ntp,finger are services... and these services are mapped to the port numbers. In *ix OS you will find these services and port numbers in
/etc/services file.

bjw5d6Author Commented:
Yes, I know this but isn't the service name needed to get the port number... for
example the part of my program...
      // Map service name to port number
      if(pse=getservbyname(service, transport))
            sin.sin_port= pse->s_port;
needs a service name and a transport (the transport is 'tcp')... I can't just use
sin.sin_port=pse->s_port; to get a default port number... or can I?
murugesandinsC C++ Shell script AIX CYGWIN_NT HP-UX Linux MINGW SunOSCommented:
(pse=getservbyname(service, transport))
the function getservbyname returns a servent structure for the line from /etc/services that matches  the  service name using protocol 'transport'. If you are not able to get the port number check ur /etc/services file that you have proper settings for getting the port number for the particular service.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bjw5d6Author Commented:
Since I made up my own service I had to enter in a made up port number.  I just
used port number 40947.  Thanks for your help anyway!  I appreciate it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.