Article View: borland.public.cppbuilder.internet.socket
Article #2057Re: Simple Client - Server example for Builder 4.0 ?
From: Bob Gonder
Date: Wed, 30 Aug 2006 14:02
Date: Wed, 30 Aug 2006 14:02
98 lines
3804 bytes
3804 bytes
Ori wrote:
>
>>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
Well, that's not what I told you to do.
First, remove getaddrinfo, and all references to it.
And all addrinfo variables.
And all code that use them.
And all code that checks the return for errors from getaddrinfo.
Obliterate addrinfo from the program.
Then. you will be left with a ListenSocket = socket(); because
"result" is an addrinfo which you have deleted.
You will re-write that one function as
ListenSocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
>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 );
Why are you doing iResult?
Is that what I wrote above?
>
>the error code keep changing all the time, it's looks like it's
That's because it isn't an error code. It is a socket handle.
Read the actual description of the functions you are using.
>void __fastcall TForm1::SpeedButton1Click( TObject *Sender )
>{
> WSADATA wsaData;
> SOCKET ConnectSocket = INVALID_SOCKET;
Remove addrinfo
////> 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;
> }
>
Remove addrinfo
////> 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);
This isn't what I said to do
////> iResult = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
>
Remove addrinfo
////> if ( iResult != 0 )
////> {
////> printf( "getaddrinfo failed: %d\n", iResult );
////> WSACleanup();
////> return;
////> }
>
> .
Down here somewhere is the line I told you to replace
> .
> .
> .
> .
>}
Technical Details
Message-ID:
<hu5bf29caejaqso6ra44tvvsdrceq0da7q@4ax.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.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-mailReferences:
<44f40396$1@newsgroups.borland.com> <o7r8f25cmlkhdcn9rvunm917gse9ch9ecl@4ax.com> <44f541e2$1@newsgroups.borland.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: Bob Gonder <notbg@notmindspring.invalid> Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: Simple Client - Server example for Builder 4.0 ? Date: Wed, 30 Aug 2006 07:02:46 -0700 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <hu5bf29caejaqso6ra44tvvsdrceq0da7q@4ax.com> References: <44f40396$1@newsgroups.borland.com> <o7r8f25cmlkhdcn9rvunm917gse9ch9ecl@4ax.com> <44f541e2$1@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 69.69.87.29 X-Trace: newsgroups.borland.com 1156946563 69.69.87.29 (30 Aug 2006 07:02:43 -0700) Lines: 99 Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.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