/* On Solaris, add -lsocket -lnsl to your compile command. */


void send_soc( int soc, char *line )
{
 int nlen, i=0, j, strt, nl, it;
 char siz, hndshk[2];

 do
  {
   strt = i;
   while ((line[i]!='\0') && (line[i]!='\n')) i = i + 1;
   if (line[i]=='\n') { nl = 1; line[i] = '\0'; } else nl = 0;
   if (i!=strt)
    {
     read( soc, hndshk, 1);
     nlen = strlen( &(line[strt]) ) + 1;
     siz = (char)nlen;
     it = write( soc, &siz, 1);
     if (it!=1) {printf("WERROR: it!=1 but = %d\n", it); scanf("%d",&it);} 
     it = write( soc, &(line[strt]), nlen);
     if (it!=nlen) {printf("WERROR: it!=%d but = %d\n", nlen, it); scanf("%d",&it);} 
    }
   if (nl) line[i] = '\n';
   i = i + 1;
  }
 while (nl);
}



void close_soc( int soc )
{
 send_soc( soc, "EndOfSocket" );
 close( soc );
}

