Article View: be.comp.programming
Article #13841HELP WITH SOCKET IN C
From: Misra
Date: Tue, 29 May 2001 16:53
Date: Tue, 29 May 2001 16:53
50 lines
1975 bytes
1975 bytes
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:
<9f0lp7$1j1ff$1@ID-67106.news.dfncis.de>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!skynet.be!fu-berlin.de!uni-berlin.de!203.199.236.28!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fcea4,25dfc4a0520414ec,start X-Google-Attributes: gidfcea4,public X-Google-ArrivalTime: 2001-05-29 10:24:03 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!skynet.be!fu-berlin.de!uni-berlin.de!203.199.236.28!not-for-mail From: "Misra" <zxxx999xxxz@yahoo.com> Newsgroups: be.comp.programming Subject: HELP WITH SOCKET IN C Date: Tue, 29 May 2001 22:23:58 +0530 Lines: 53 Message-ID: <9f0lp7$1j1ff$1@ID-67106.news.dfncis.de> NNTP-Posting-Host: 203.199.236.28 X-Trace: fu-berlin.de 991156840 1672687 203.199.236.28 (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