🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #13842

Re: HELP WITH SOCKET IN C

#13842
From: Luc Kumps
Date: Tue, 29 May 2001 17:25
71 lines
2705 bytes
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: <lYQQ6.19798$X03.1687837@afrodite.telenet-ops.be>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!newsfeed2.skycache.com!newsfeed.skycache.com!Cidera!skynet.be!newsfeeds.belnet.be!news.belnet.be!afrodite.telenet-ops.be!not-for-mail
References: <9f0lp7$1j1ff$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 10:27:24 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!newsfeed2.skycache.com!newsfeed.skycache.com!Cidera!skynet.be!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>
Subject: Re: HELP WITH SOCKET IN C
Lines: 73
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: <lYQQ6.19798$X03.1687837@afrodite.telenet-ops.be>
Date: Tue, 29 May 2001 17:25:37 GMT
NNTP-Posting-Host: 213.118.69.38
X-Complaints-To: abuse@pandora.be
X-Trace: afrodite.telenet-ops.be 991157137 213.118.69.38 (Tue, 29 May 2001 19:25:37 MET DST)
NNTP-Posting-Date: Tue, 29 May 2001 19:25:37 MET DST
Organization: Telenet Internet