The meaning of daemon xinetd and socket program

Source: Internet
Author: User
Tags printf socket stdin

1.XINETD provides passive super service, that is, the service program is started by the use of the end, usually need not exist. For example, FTP, telnetd, Pop3,imap, Auth, and so on, these services are not used when people do not need to start. In addition, XINETD converts the socket to stdin/stdout, which simplifies the design of the Web service program, allowing you to complete the processing of very complex network protocols using only printf and fgets.

2. A simple service program goodie

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
Char *cmds[]={
"Help",
"Say",
"Hello",
"Bye",
"Exit",
Null
};
int Getcmd (char *cmd)
{
int n=0;
while (Cmds[n]!=null) {
if (strncasecmp (Cmd,cmds[n],strlen (cmds[n)) ==0) return n;
n++;
}
return-1;
}
void Main (void)
{
Char buf[1024];
int OK;
printf ("Welcome to Goodie service!");
Fflush (stdout);
ok=0;
do {
while (Fgets (Buf,1023,stdin) ==null);
Switch (Getcmd (BUF)) {
Case-1: printf ("Unknown command!"); Break
Case 0:
printf ("How may I help, sir?");
int j=0;
while (cmds[j++]!=null) printf ("%s\t\t", cmds[j-1]);
Break
Case 1:printf ("I'll say%s", &buf[3]); Break
Case 2:printf ("How ' re you doing today?"); Break
Case 3:printf ("Si ya, mate!"); ok=1; Break
Case 4:printf ("Go ahead!"); ok=1; Break
}
Fflush (stdout);
while (!ok);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.