Article View: borland.public.cppbuilder.internet.socket
Article #5358Re: Problem with sending data with TCS/TSS (data has been received mixed and/or damaged)
From: Vladimir Stefanovic
Date: Fri, 20 Aug 2004 08:47
Date: Fri, 20 Aug 2004 08:47
78 lines
3598 bytes
3598 bytes
>Uh, I hope this will work
Yes, It worked perfectly...
I have read one of your posts some time ago...
> the client-side code you currently have will not work
> as-is if you are using non-blocking mode, because you
> are not checking for when SendBuffer() fails to send
> any data due to blocking. When that happens, you have
> to wait for the OnWrite event to trigger before you can
> send more data again. Otherwise, you are going to corrupt
> your data stream because not all of the data will be sent
> correctly.
... and I have the same situation in NonBlocking mode. How
can I addopt the code I have, to work synchronized with
OnWrite(), or I have to take a completely different approach?
Should that change also affect the servers receiving mechanism?
BYTE Buffer [ BUFFER_SIZE ];
int CurrentPosition = 0;
int Delta;
while ( ( Delta = OutboxDataBuffer->Size - CurrentPosition ) > 0 )
{
int NumberOfBytesRead = ( Delta < BUFFER_SIZE ? Delta : BUFFER_SIZE );
OutboxDataBuffer->Seek( CurrentPosition, soFromBeginning );
OutboxDataBuffer->ReadBuffer( Buffer, NumberOfBytesRead );
int NumberOfBytesSent = ClientSocket->Socket->SendBuf( Buffer, NumberOfBytesRead );
if ( NumberOfBytesSent < 1 ) // <--- this happens in non-blocking mode after 8K
return; // Error ...
CurrentPosition += NumberOfBytesSent;
}
Just one more thing:
I thought that within Open/Close...
ClientSocket->Open()
ClientSocket->Socket->SendBuf()
ClientSocket->Close()
... I am addressing the same unique ServerSocketClientRead
instance:
void __fastcall TserverForm::ServerSocketClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
// ...
int NewSize;
// ... NewSize increases ...
this->Caption = IntToStr ( NewSize );
}
... but when Closed() and again Opened(), 'NewSize' continues
counting like it is static! In fact 'NewSize' continues counting
for all clients' connections when sending. I realize that this
must have some sense and I'm trying to figure it out. Is that
in connection with servers' blocking modes?
All this I need to find out the way how to:
* Deploy and recognize connection of a speciffic client and
somehow make it's own TMemoryStream for receiving, decoding
and adding to the shared list (with critical section involved).
* Inform the server what stream size to expect (embed that
into stream, for example first 10 bytes ASCII, or a separate
call)
Best regards,
Vladimir Stefanovic
Technical Details
Message-ID:
<4125baa0$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<41245031$1@newsgroups.borland.com> <4124d7ab@newsgroups.borland.com> <4124f2ca@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,9d2d5d657ea2710a X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Vladimir Stefanovic" <antivari@ptt.yu> Sender: "Vladimir Stefanovic" <antivari@ptt.yu> Reply-To: "Vladimir Stefanovic" <antivari@ptt.yu> Subject: Re: Problem with sending data with TCS/TSS (data has been received mixed and/or damaged) Newsgroups: borland.public.cppbuilder.internet.socket X-User-Info: 213.137.116.190 X-Forwarded-For: 128.128.129.165 References: <41245031$1@newsgroups.borland.com> <4124d7ab@newsgroups.borland.com> <4124f2ca@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <4125baa0$1@newsgroups.borland.com> Date: 20 Aug 2004 01:47:28 -0700 X-Trace: newsgroups.borland.com 1092991648 207.105.83.66 (20 Aug 2004 01:47:28 -0700) Lines: 79 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail