public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Socket - connect problem: The descriptor is a file, not a socket
@ 2000-06-05 10:26 Parker, Ron
  0 siblings, 0 replies; 3+ messages in thread
From: Parker, Ron @ 2000-06-05 10:26 UTC (permalink / raw)
  To: Peter P. Mooring, 'cygwin@sourceware.cygnus.com'

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@xs4all.nl ]
Sent: Sunday, June 04, 2000 6:05 AM
To: cygwin@sourceware.cygnus.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@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: Socket - connect problem: The descriptor is a file, not a socket
@ 2000-06-05 15:12 Heribert Dahms
  0 siblings, 0 replies; 3+ messages in thread
From: Heribert Dahms @ 2000-06-05 15:12 UTC (permalink / raw)
  To: 'Parker, Ron',
	Peter P. Mooring, 'cygwin@sourceware.cygnus.com'

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

Bye, Heribert (heribert_dahms@icon-gmbh.de)

> -----Original Message-----
> From:	Parker, Ron [SMTP:rdparker@butlermfg.com]
> Sent:	Monday, June 05, 2000 19:23
> To:	Peter P. Mooring; 'cygwin@sourceware.cygnus.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@xs4all.nl ]
> Sent: Sunday, June 04, 2000 6:05 AM
> To: cygwin@sourceware.cygnus.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@sourceware.cygnus.com

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Socket - connect problem: The descriptor is a file, not a socket
@ 2000-06-04  3:58 Peter P. Mooring
  0 siblings, 0 replies; 3+ messages in thread
From: Peter P. Mooring @ 2000-06-04  3:58 UTC (permalink / raw)
  To: cygwin

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3278 bytes --]

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, t hanks,
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 */
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-06-05 15:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-05 10:26 Socket - connect problem: The descriptor is a file, not a socket Parker, Ron
  -- strict thread matches above, loose matches on Subject: below --
2000-06-05 15:12 Heribert Dahms
2000-06-04  3:58 Peter P. Mooring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).