Logo 
Search:

Networking Articles

Submit Article
Home » Articles » Networking » TCP/IPRSS Feeds

TCP/IP program of TCP client for DAYTIME service and invoke Daytime on specified host and print results

Posted By: Milind Mishra     Category: Networking     Views: 3131

TCP/IP program of TCP client for DAYTIME service and invoke Daytime on specified host and print results.

Code for TCP/IP program of TCP client for DAYTIME service and invoke Daytime on specified host and print results in Networking

/* TCPdaytime.c - TCPdaytime, main */

#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

externint    errno;

int    TCPdaytime(constchar *host, constchar *service);
int    errexit(constchar *format, ...);
int    connectTCP(constchar *host, constchar *service);

#define    LINELEN        128

/*------------------------------------------------------------------------ * main - TCP client for DAYTIME service *------------------------------------------------------------------------ */int
main(int argc, char *argv[])
{
    char    *host = "localhost";    /* host to use if none supplied    */char    *service = "daytime";    /* default service port        */switch (argc) {
    case 1:
        host = "localhost";
        break;
    case 3:
        service = argv[2];
        /* FALL THROUGH */case 2:
        host = argv[1];
        break;
    default:
        fprintf(stderr, "usage: TCPdaytime [host [port]]\n");
        exit(1);
    }
    TCPdaytime(host, service);
    exit(0);
}

/*------------------------------------------------------------------------ * TCPdaytime - invoke Daytime on specified host and print results *------------------------------------------------------------------------ */
TCPdaytime(constchar *host, constchar *service)
{
    char    buf[LINELEN+1];        /* buffer for one line of text    */int    s, n;            /* socket, read count        */

    s = connectTCP(host, service);

    while( (n = read(s, buf, LINELEN)) > 0) {
        buf[n] = '\0';        /* ensure null-terminated    */
        (void) fputs( buf, stdout );
    }
}
  
Share: 



Milind Mishra
Milind Mishra author of TCP/IP program of TCP client for DAYTIME service and invoke Daytime on specified host and print results is from India.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!