Message-Id: <200006051727.NAA12247@delorie.com> Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com From: "Parker, Ron" To: "Peter P. Mooring" , "'cygwin AT sourceware DOT cygnus DOT com'" Subject: Socket - connect problem: The descriptor is a file, not a socket Date: Mon, 5 Jun 2000 12:22:51 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2448.0) Content-Type: text/plain 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 #include #include #include #include #include #include #include #include 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