www.sas.com > Service and Support > Technical Support
 
Technical Support SAS - The power to know(tm)
  TS Home | Intro to Services | News and Info | Contact TS | Site Map | FAQ | Feedback


/*---------------------------------------------------------------------+
|                Copyright (c) 1995, SAS Institute Inc.                |
|                  Unpublished - All Rights Reserved                   |
|                      S A S / C   S A M P L E                         |
|                                                                      |
|         NAME: TCPTSERV                                               |
|     LANGUAGE: C                                                      |
|      PURPOSE: Demonstrate a TCP Server, attached by TCPLISTN. The    |
|               "sub-task" will issue a takesocket(), and write to the |
|               remote client application.                             |
|   MVS -                                                              |
|      COMPILE, LINK: SUBMIT prefix.SAMPLE.AUX(TCPTSERV)               |
|               where "prefix" is the installation defined high-level- |
|               qualifier for the SAS/C product.                       |
|      EXECUTE: N/A - TCPTSERV is "attached" by TCPLISTN               |
|        NOTES: TCPTSERV assumes a working TCP/IP environment on both  |
|               the local and remote hosts, refer to MISC NOTES.       |
|   TSO -                                                              |
|      COMPILE: LC370 CLIST - options ENXREF EXTNAME RENT              |
|         LINK: CLK370 CLIST                                           |
|      EXECUTE: N/A - TCPTSERV is "attached" by TCPLISTN               |
|        NOTES: TCPTSERV assumes a working TCP/IP environment on both  |
|               the local and remote hosts. Refer to MISC NOTES:       |
|   CMS -                                                              |
|      COMPILE: LC370 EXEC - options ENXREF EXTNAME RENT               |
|         LINK: CLINK EXEC                                             |
|      EXECUTE: TCPTSERV                                               |
|        NOTES: TCPTSERV assumes a working TCP/IP environment on both  |
|               the local and remote hosts. Refer to MISC NOTES:       |
|        NOTES: TCPTSERV may be executed stand-alone. In this          |
|               environment, customize TIMEPORT. A client application  |
|               using TCPTSERV in this instance will only need to do a |
|               socket(), connect(), recv() and close(). The TCPCLNT   |
|               may be modified to test TCPTSERV independently.        |
|   MISC NOTES: Use TCPCLNT to test TCPLISTN and TCPTSERV              |
|   MISC NOTES: TCPTSERV uses the following environment variables:     |
|               TCP_SOCK   - Socket descriptor passed to TCPTSERV      |
|               TCP_DOMAIN - AF_INET = 2, passed to TCPTSERV           |
|               TCP_NAME   - Listener Jobname, passed to TCPTSERV      |
|               TCP_SUBTASKNAME - taskname from getclientid() passed   |
|                            to TCPTSERV.                              |
+---------------------------------------------------------------------*/

#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <options.h>
#if  __SASC__ == 550
   #include <fcntl.h>
#else
   #include <unistd.h>
#endif

int GetSocket(int *cs);

#define TIMEPORT 0   /* default listen() port if NOT attached */
#define TCP_SOCK_FAILED   -1    /* generic return for failed request */

main(int argc, void **argv)
{
   int cs=0;
   int i;

   /* Variables used to obtain the time.                  */
   char *p;
   int len;
   time_t t;

   /* Loop count */
   int n_times;

   /* Buffer for outgoing time string.                    */
   char outbuf[128];

   /* If there were any arguments passed, echo them  */
   if (argc >1)
      {
      for (i=0; i
Copyright (c) 2000 SAS Institute Inc. All Rights Reserved.
Terms of Use & Legal Information | Privacy Statement