Solved

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

Posted on 2004-10-24
255 Views
Last Modified: 2010-04-17

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];
                        break;
            case 3: service = argv[1];
                        host = argv[2];
                        break;
            default: errexit("usage: TCPmusic[port]\n");
AND SO ON....ETC...

Thanks,
0
Question by:bjw5d6
    4 Comments
     
    LVL 7

    Assisted Solution

    by:Murugesan Nagarajan
    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.

    HTH
    0
     

    Author Comment

    by:bjw5d6
    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?
    0
     
    LVL 7

    Accepted Solution

    by:
    Here
    (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.
    0
     

    Author Comment

    by:bjw5d6
    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.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    877 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now