Article View: be.comp.programming
Article #13848Re: HELP WITH SOCKET IN C
From: Luc Kumps
Date: Tue, 29 May 2001 21:17
Date: Tue, 29 May 2001 21:17
187 lines
6025 bytes
6025 bytes
Could you please show the actual source code that's still giving errors.
You should insert the code I gave you between your original lines:
> > > struct sockaddr_in their_addr;
struct WSAData WSAD;
if (WSAStartup(0x0101,&WSAD)!=0) {
printf("WSAStartup failed\n");
exit(1);
}
> > > memset(&my_addr,0,sizeof(struct sockaddr_in));
Luc
"Misra" <zxxx999xxxz@yahoo.com> wrote in message
news:9f0qur$1jpov$1@ID-67106.news.dfncis.de...
> 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:
<ilUQ6.20119$X03.1791188@afrodite.telenet-ops.be>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-03!supernews.com!mtu.ru!sunqbc.risq.qc.ca!newsfeeds.belnet.be!news.belnet.be!afrodite.telenet-ops.be!not-for-mailReferences:
<9f0lp7$1j1ff$1@ID-67106.news.dfncis.de> <lYQQ6.19798$X03.1687837@afrodite.telenet-ops.be> <9f0qur$1jpov$1@ID-67106.news.dfncis.de>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 14:22:05 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-03!supernews.com!mtu.ru!sunqbc.risq.qc.ca!newsfeeds.belnet.be!news.belnet.be!afrodite.telenet-ops.be!not-for-mail From: "Luc Kumps" <NOkumpsSPAM@pandora.be> Newsgroups: be.comp.programming References: <9f0lp7$1j1ff$1@ID-67106.news.dfncis.de> <lYQQ6.19798$X03.1687837@afrodite.telenet-ops.be> <9f0qur$1jpov$1@ID-67106.news.dfncis.de> Subject: Re: HELP WITH SOCKET IN C Lines: 189 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 Message-ID: <ilUQ6.20119$X03.1791188@afrodite.telenet-ops.be> Date: Tue, 29 May 2001 21:17:02 GMT NNTP-Posting-Host: 213.118.69.38 X-Complaints-To: abuse@pandora.be X-Trace: afrodite.telenet-ops.be 991171022 213.118.69.38 (Tue, 29 May 2001 23:17:02 MET DST) NNTP-Posting-Date: Tue, 29 May 2001 23:17:02 MET DST Organization: Telenet Internet