Article View: be.comp.programming
Article #13844Re: HELP WITH SOCKET IN C
From: Misra
Date: Tue, 29 May 2001 18:29
Date: Tue, 29 May 2001 18:29
165 lines
5004 bytes
5004 bytes
hi,
thanks for the tip. I tried it. but I am still getting errors.First I put
the lines inside main. It gave me a error "this declaration is not allowed
inside . SO I placed it outside main. Still I am getting errors. My
winsock.dll version is 4.10.1656
----- Original Message -----
From: "Luc Kumps" <NOkumpsSPAM@pandora.be>
Newsgroups: be.comp.programming
Sent: Tuesday, May 29, 2001 10:55 PM
Subject: Re: HELP WITH SOCKET IN C
> You forgot to call WSAStartup, which is necessary to initialize the
Windows
> socket library.
> Just add this add the start of your program:
>
> struct WSAData WSAD;
>
> if (WSAStartup(0x0101,&WSAD)!=0) {
> printf("WSAStartup failed\n");
> exit(1);
> }
>
>
> Luc
>
>
>
> "Misra" <zxxx999xxxz@yahoo.com> wrote in message
> news:9f0lp7$1j1ff$1@ID-67106.news.dfncis.de...
> > Hi,
> > Please tell me why this piece of code in C is not working. I am using
the
> > free version of Borland c++5.5 compiler available for download. When I
> > execute the .exe file the socket descriptor returns a value of -1 . I am
> > using win 95.
> >
> >
> > #include<winsock.h>
> > #include<windows.h>
> > #include<stdio.h>
> > #include<string.h>
> >
> > int main(void)
> > {
> > SOCKET sockdesc,new_sd;
> > int theirsize;
> > struct sockaddr_in my_addr;
> > struct sockaddr_in their_addr;
> >
> > memset(&my_addr,0,sizeof(struct sockaddr_in));
> > // memset(&their_addr,0,sizeof(struct sockaddr_in));
> >
> >
> > my_addr.sin_family=AF_INET;
> > my_addr.sin_addr.s_addr=htonl(INADDR_ANY);
> > my_addr.sin_port=htons(23);
> >
> > sockdesc=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
> >
> > printf("err in socket %d \n",sockdesc);
> >
> >
> >
> > if((bind(sockdesc,(struct sockaddr *) &my_addr,sizeof(struct
> > sockaddr_in)))<0)
> > {
> > printf("err in bind \n");
> > }
> >
> > if((listen(sockdesc,2))<0)
> > {
> > printf("err in listen");
> > }
> > theirsize=sizeof(struct sockaddr_in);
> > new_sd=accept(sockdesc,&their_addr,&theirsize);
> > if(new_sd<0)
> > {
> > printf("err in accept %d \n",new_sd);
> > }
> > }
> >
> >
> >
>
>
"Luc Kumps" <NOkumpsSPAM@pandora.be> wrote in message
news:lYQQ6.19798$X03.1687837@afrodite.telenet-ops.be...
> You forgot to call WSAStartup, which is necessary to initialize the
Windows
> socket library.
> Just add this add the start of your program:
>
> struct WSAData WSAD;
>
> if (WSAStartup(0x0101,&WSAD)!=0) {
> printf("WSAStartup failed\n");
> exit(1);
> }
>
>
> Luc
>
>
>
> "Misra" <zxxx999xxxz@yahoo.com> wrote in message
> news:9f0lp7$1j1ff$1@ID-67106.news.dfncis.de...
> > Hi,
> > Please tell me why this piece of code in C is not working. I am using
the
> > free version of Borland c++5.5 compiler available for download. When I
> > execute the .exe file the socket descriptor returns a value of -1 . I am
> > using win 95.
> >
> >
> > #include<winsock.h>
> > #include<windows.h>
> > #include<stdio.h>
> > #include<string.h>
> >
> > int main(void)
> > {
> > SOCKET sockdesc,new_sd;
> > int theirsize;
> > struct sockaddr_in my_addr;
> > struct sockaddr_in their_addr;
> >
> > memset(&my_addr,0,sizeof(struct sockaddr_in));
> > // memset(&their_addr,0,sizeof(struct sockaddr_in));
> >
> >
> > my_addr.sin_family=AF_INET;
> > my_addr.sin_addr.s_addr=htonl(INADDR_ANY);
> > my_addr.sin_port=htons(23);
> >
> > sockdesc=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
> >
> > printf("err in socket %d \n",sockdesc);
> >
> >
> >
> > if((bind(sockdesc,(struct sockaddr *) &my_addr,sizeof(struct
> > sockaddr_in)))<0)
> > {
> > printf("err in bind \n");
> > }
> >
> > if((listen(sockdesc,2))<0)
> > {
> > printf("err in listen");
> > }
> > theirsize=sizeof(struct sockaddr_in);
> > new_sd=accept(sockdesc,&their_addr,&theirsize);
> > if(new_sd<0)
> > {
> > printf("err in accept %d \n",new_sd);
> > }
> > }
> >
> >
> >
>
>
Technical Details
Message-ID:
<9f0qur$1jpov$1@ID-67106.news.dfncis.de>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-03!supernews.com!nntp.cs.ubc.ca!fu-berlin.de!uni-berlin.de!203.199.238.229!not-for-mailReferences:
<9f0lp7$1j1ff$1@ID-67106.news.dfncis.de> <lYQQ6.19798$X03.1687837@afrodite.telenet-ops.be>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fcea4,25dfc4a0520414ec X-Google-Attributes: gidfcea4,public X-Google-ArrivalTime: 2001-05-29 11:50:08 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-03!supernews.com!nntp.cs.ubc.ca!fu-berlin.de!uni-berlin.de!203.199.238.229!not-for-mail From: "Misra" <zxxx999xxxz@yahoo.com> Newsgroups: be.comp.programming Subject: Re: HELP WITH SOCKET IN C Date: Tue, 29 May 2001 23:59:10 +0530 Lines: 169 Message-ID: <9f0qur$1jpov$1@ID-67106.news.dfncis.de> References: <9f0lp7$1j1ff$1@ID-67106.news.dfncis.de> <lYQQ6.19798$X03.1687837@afrodite.telenet-ops.be> NNTP-Posting-Host: 203.199.238.229 X-Trace: fu-berlin.de 991162141 1697567 203.199.238.229 (16 [67106]) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400