Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-24
4
Medium Priority
?
272 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
Comment
Question by:bjw5d6
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 9

Assisted Solution

by:Murugesan Nagarajan
Murugesan Nagarajan earned 250 total points
ID: 12398333
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
ID: 12402419
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 9

Accepted Solution

by:
Murugesan Nagarajan earned 250 total points
ID: 12407602
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
ID: 12455020
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Make the most of your online learning experience.
Six Sigma Control Plans
Introduction to Processes

610 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