🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #13768

Re: HELP WITH SOCKET IN C

#13768
From: Luc Kumps
Date: Fri, 01 Jun 2001 07:24
289 lines
8946 bytes
You should replace

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR
lpszCmdLine,int nCmdShow)

by

void main(int argc, char **argv)

Luc

"Misra" <zxxx999xxxz@yahoo.com> wrote in message
news:9f62jm$2dru1$2@ID-67106.news.dfncis.de...
> Hi Luc,
>   The program is compiling with a different compiler . But with Borland
C++
> 5.5 it still refuses to compile . It gives the error "Unresolved external
> '_main' referenced from c:\borland\bcc55\lib\cox32.obj". With a different
> compiler it compiles perfectly . Can you tell me why it does not compile
> with BC++ 5.5 . The code is as follows:
>
> #include<winsock.h>
> #include<windows.h>
> #include<stdio.h>
> #include<string.h>
>
>
> #include <shellapi.h>
> #include <stdlib.h>
>
>
> struct WSAData WSAD;
>
>
> int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR
> lpszCmdLine,int nCmdShow)
>    {
>
>
>
>    SOCKET sockdesc,new_sd;
>    int theirsize;
>    struct sockaddr_in my_addr;
>    struct sockaddr_in their_addr;
>    WSAStartup( MAKEWORD( 1, 1 ),&WSAD);
>    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,0);
>    if(sockdesc<0)
>     {
>    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:ilUQ6.20119$X03.1791188@afrodite.telenet-ops.be...
> > 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: <DqHR6.25484$X03.2629126@afrodite.telenet-ops.be>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!fr.clara.net!heighliner.fr.clara.net!newsfeeds.belnet.be!news.belnet.be!afrodite.telenet-ops.be!not-for-mail
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> <ilUQ6.20119$X03.1791188@afrodite.telenet-ops.be> <9f62jm$2dru1$2@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-06-01 00:30:40 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!fr.clara.net!heighliner.fr.clara.net!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> <ilUQ6.20119$X03.1791188@afrodite.telenet-ops.be> <9f62jm$2dru1$2@ID-67106.news.dfncis.de>
Subject: Re: HELP WITH SOCKET IN C
Lines: 291
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: <DqHR6.25484$X03.2629126@afrodite.telenet-ops.be>
Date: Fri, 01 Jun 2001 07:24:19 GMT
NNTP-Posting-Host: 213.118.67.64
X-Complaints-To: abuse@pandora.be
X-Trace: afrodite.telenet-ops.be 991380259 213.118.67.64 (Fri, 01 Jun 2001 09:24:19 MET DST)
NNTP-Posting-Date: Fri, 01 Jun 2001 09:24:19 MET DST
Organization: Telenet Internet