🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Trouble with TcpClient component

#74
From: Remy Lebeau (TeamB)
Date: Mon, 21 Apr 2008 16:36
67 lines
3866 bytes
"Carlos Moreno" <moreno_h3gd@mochima.com> wrote in message 
news:480cb8b5$1@newsgroups.borland.com...

> The short story / bottom line:  how can I emulate the non-
> blocking functionality of TClientSocket, where I transmit
> whenever I need to transmit, and get an event whenever the
> socket received data from the server?

TClientSocket is deprecated, but it is still available in BCB 2007 (install 
the dclsockets100.bpl packet), and works the same as it did before.

> TClientSocket is not supported in C++B2007

Yes, it is.  IT is simply not installed by default anymore.

> and the closest thing seems to be TcpClient

TTcpClient is nowhere even close to TClientSocket.  They are very different. 
TTcpClient was created at a time when Borland was trying to write its own 
cross-platform socket classes.  Those classes were not implemented very 
well, though, and lack a LOT of functionality.  I strongly recommend not 
using them at all.  Stick with TClientSocket instead, or else use a 
third-party sockt library instead, such as Indy, ICS, or Synapse.

> I pretty much ignore the OnSend event

That is a mistake, especially since you were using a non-blocking socket. 
If you trying to pass too much data to TClientSocket at one time, 
SendBuf/Text() fails with a return code of -1 and WSAGetLastError() returns 
WSAEWOULDBLOCK.  In that situation, you need to wait for the OnSend event to 
fire before you can pass any further data to the socket - including 
re-sending the data that triggered the blockage in the first place!  A lot 
of TClientSocket (and TServerSocket) users ignore that fact when they 
shouldn't be.

> as that one simply tells me that I *can* transmit --- I simply transmit
> when the user triggers an action that requires transmitting.

But that is still not a guarantee that the socket will be able to accept 
everything you tell it to transmit.  If it doesn't, and if you do not handle 
it properly, then you will corrupt your communications with the other party.

> The little it says suggests that it works exactly the same;

TTcpClient does not work like TClientSocket, not even close.

> The thing is, I never get an OnReceive event

TTcpClient DOES NOT have asynchronous events at all!!!

> well, I do, but I do get it in response to my call to ReceiveBuf

Which is exactly how TTcpClient is coded to work.  You will NOT get the 
OnReceive event asynchronously!  You have to continuously invoke your own 
reading operations, and then TTcpClient will read whatever is available at 
the time.

> clearly, I need it to be the other way around;  I would only
> call ReceveiBuf when I'm notified, via an event, that the
> socket just received data)

There are no asynchronous notifications in TTcpClient.  Which is one of the 
reasons why I hate that component and never advise anyone to use it.


Gambit 
Technical Details
Message-ID: <480cc2b6$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder.news-service.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <480cb8b5$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,9f8efd9a63590eec
X-Google-Attributes: gid11508e,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <480cb8b5$1@newsgroups.borland.com>
Subject: Re: Trouble with TcpClient component
Date: Mon, 21 Apr 2008 09:36:54 -0700
Lines: 69
Organization: Lebeau Software
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
NNTP-Posting-Host: 207.178.157.90
Message-ID: <480cc2b6$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1208795830 207.178.157.90 (21 Apr 2008 09:37:10 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder.news-service.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail