🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #2056

Re: Simple Client - Server example for Builder 4.0 ?

#2056
From: Ori
Date: Wed, 30 Aug 2006 07:44
75 lines
3009 bytes
>The MSDN links you posted should work for you once you remove the
>function that doesn't compile (getaddrinfo), and replace
>
>    ListenSocket = socket(result->ai_family, result->ai_socktype,
>result->ai_protocol);
>
>with
>
>   ListenSocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );


Hi Bob, I'm still having problems with this code, after I 
replaced the function that you told me I still had more errors 
and warnings, for example it don't know the function 
freeaddrinfo() so I just deleted it, after I managed at last to 
run the code then the program return from the function with an 
error after the line - 

 iResult = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); 

the error code keep changing all the time, it's looks like it's 
rising each time when I do "Build all", for example if I run 
the program several times I'm getting the same error code, but
once when I do "Build all" and tun it again I get another error
code, here are some of the error codes that I got - 

 15196, 17244, 19292, 21340....

What can be the problem? here is my code until the return point 
with the error - 


void __fastcall TForm1::SpeedButton1Click( TObject *Sender )
{
  WSADATA wsaData;
  SOCKET ConnectSocket = INVALID_SOCKET;
  struct addrinfo *result = NULL, *ptr = NULL, hints;
  char *sendbuf = "this is a test";
  char recvbuf[DEFAULT_BUFLEN];
  int iResult;
  int recvbuflen = DEFAULT_BUFLEN;

  // Validate the parameters
  // Initialize Winsock
  iResult = WSAStartup( MAKEWORD( 2, 2 ), &wsaData );

  if ( iResult != 0 )
  {
    printf( "WSAStartup failed: %d\n", iResult );
    return;
  }

  ZeroMemory( &hints, sizeof(hints) );
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_protocol = IPPROTO_TCP;

//Resolve the server address and port
//iResult = getaddrinfo(argv[1], DEFAULT_PORT, &hints, &result);
  iResult = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );

  if ( iResult != 0 )
  {
    printf( "getaddrinfo failed: %d\n", iResult );
    WSACleanup();
    return;
  }

   .  
   .  
   .  
   .  
   .  
}
Technical Details
Message-ID: <44f541e2$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <44f40396$1@newsgroups.borland.com> <o7r8f25cmlkhdcn9rvunm917gse9ch9ecl@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,c28846b9a9f67c3c
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Ori" <Ori@Homepage.com>
Sender: "Ori" <Ori@Homepage.com>
Reply-To: "Ori" <Ori@Homepage.com>
Subject: Re: Simple Client - Server example for Builder 4.0  ?
Newsgroups: borland.public.cppbuilder.internet.socket
X-User-Info: 62.0.27.159     
References: <44f40396$1@newsgroups.borland.com> <o7r8f25cmlkhdcn9rvunm917gse9ch9ecl@4ax.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <44f541e2$1@newsgroups.borland.com>
Date: 30 Aug 2006 00:44:34 -0700
X-Trace: newsgroups.borland.com 1156923874 207.105.83.66 (30 Aug 2006 00:44:34 -0700)
Lines: 76
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail