delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/06/05/18:13:04

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
Message-ID: <99B82AA9708ED0119B55006097125A00363EAC@ifk63.mach.uni-karlsruhe.de>
From: Heribert Dahms <heribert_dahms AT icon-gmbh DOT de>
To: "'Parker, Ron'" <rdparker AT butlermfg DOT com>,
"Peter P. Mooring"
<peterpm AT xs4all DOT nl>,
"'cygwin AT sourceware DOT cygnus DOT com'"
<cygwin AT sourceware DOT cygnus DOT com>
Subject: RE: Socket - connect problem: The descriptor is a file, not a soc
ket
Date: Tue, 6 Jun 2000 00:09:03 +0200
X-Priority: 3
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.0.1457.3)

BTW, Peter should put his FD_ZERO/FD_SET inside the loop for best
portability.

Bye, Heribert (heribert_dahms AT icon-gmbh DOT de)

> -----Original Message-----
> From:	Parker, Ron [SMTP:rdparker AT butlermfg DOT com]
> Sent:	Monday, June 05, 2000 19:23
> To:	Peter P. Mooring; 'cygwin AT sourceware DOT cygnus DOT com'
> Subject:	Socket - connect problem: The descriptor is a file, not
> a socket
> 
> If I had to guess, it sounds your program is somehow calling the
> Microsoft
> WinSock version of select instead of the cygwin one.  If you could
> give the
> actual commands that were used to compile and link it might help.
> 
> (I have included the text of the original message with all of the HTML
> encoding removed, since I know some of the main contributors to this
> list do
> not read HTML mail.)
> 
> -----Original Message-----
> From: Peter P. Mooring [mailto:peterpm AT xs4all DOT nl]
> Sent: Sunday, June 04, 2000 6:05 AM
> To: cygwin AT sourceware DOT cygnus DOT com
> Subject: Socket - connect problem: The descriptor is a file, not a
> socket
> 
> 
> Hi all,
> For a project I need a small program using a socket to communicate
> with a
> server so I downloaded and installed cygwin/gcc, got an example
> program from
> the net and compiled (and updated in.h and compiled again). No errors.
> When I run the program (on Win98), see below, I get the message 'The
> descriptor is a file, not a socket'. I scanned the mailing lists , and
> the
> net, but am stuck. 
> Please help, thanks,
> Peter
>  
> This is the program, I call it like this 'client 1685 164.139.146.156'
>  
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <sys/time.h>
> #include <netinet/in.h>
> #include <errno.h>
> #include <ctype.h>
> #include <netdb.h>
> #include <stdio.h>
> #include <string.h>
>  
> main(argc, argv)
>  int argc;
>  char *argv[];
>  {
>  
>  struct hostent *hostp;
>  struct servent *servp; 
>  struct sockaddr_in server;
>  int sock; 
>  static struct timeval timeout = { 5, 0 };   /* five seconds */ 
>  fd_set rmask, xmask, mask;
>  char buf[BUFSIZ]; 
>         int nfound, bytesread;
>  
>  if (argc != 3) { 
>   (void) fprintf(stderr,"usage: %s service host\n",argv[0]); 
>   exit(1);
>  } 
>  if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { 
>   perror("socket");
>   exit(1);
>  } 
>         if (isdigit(argv[1][0])) {
>   static struct servent s; 
>   servp = &s; 
>   s.s_port = htons((u_short)atoi(argv[1]));
>  } else if ((servp = getservbyname(argv[1], "tcp")) == 0) { 
>   fprintf(stderr,"%s: unknown service\n",argv[1]); 
>   exit(1);
>  } 
>         if ((hostp = gethostbyname(argv[2])) == 0) { 
>   fprintf(stderr,"%s: unknown host\n",argv[2]); 
>   exit(1);
>  } 
>  memset((void *) &server, 0, sizeof server);
>  server.sin_family = AF_INET; 
>  memcpy((void *) &server.sin_addr, hostp->h_addr, hostp->h_length); 
>  server.sin_port = servp->s_port; 
>  if (connect(sock, (struct sockaddr *) &server, sizeof server) < 0) { 
>   (void) close(sock);
>   perror("connect");  
>   exit(1);
>  }
>  FD_ZERO(&mask);  
>  FD_SET(sock, &mask);
>  FD_SET(fileno(stdin), &mask); 
>  for (;;) {
>   rmask = mask; 
>   nfound = select(FD_SETSIZE, &rmask, (fd_set *)0, (fd_set *)0,
> &timeout); 
>   if (nfound < 0) {
>    if (errno == EINTR) { 
>     printf("interrupted system call\n"); 
>     continue;
>    } 
>    /* something is very wrong! */ 
>    perror("select");
>    exit(1); 
>   }
>   if (nfound == 0) { 
>    /* timer expired */ 
>    printf("Please type something!\n"); 
>    continue;
>   } 
>   if (FD_ISSET(fileno(stdin), &rmask)) { 
>    /* data from keyboard */  
>    if (!fgets(buf, sizeof buf, stdin)) {  
>     if (ferror(stdin)) { 
>      perror("stdin"); 
>      exit(1);
>     } 
>     exit(0);
>    } 
>    if (write(sock, buf, strlen(buf)) < 0) { 
>     perror("write");
>     exit(1); 
>    }
>   } 
>   if (FD_ISSET(sock,&rmask)) { 
>    /* data from network */ 
>    bytesread = read(sock, buf, sizeof buf); 
>    buf[bytesread] = '\0'; 
>    printf("%s: got %d bytes: %s\n", argv[0], bytesread, buf); 
>   }
>  }
> } /* main - client.c */
> 
> 
> --
> Want to unsubscribe from this list?
> Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019