Article View: borland.public.cppbuilder.internet.socket
Article #5251Re: Client: ctNonBlocking -> Server: stThreadBlocking
From: Hans Galema
Date: Mon, 27 Sep 2004 19:38
Date: Mon, 27 Sep 2004 19:38
63 lines
2736 bytes
2736 bytes
Vladimir Stefanovic wrote:
> How can I send data with TClientSocket in ctNonBlocking
> to Server. I have the sending code which only works when
> the mode is ctBlocking. What can I do to modify the code
> to work in ctNonBlocking mode?
As far as I see it the code will do in non-blocking mode.
What makes you say that it does not work for non-blocking ?
I have some remarks:
- Even if you try to send 4 bytes with SendBuf() then you
have to check that all 4 bytes have been sent. At the moment
you only check for -1.
- I'm not quite sure if -1 means an error. It means that
nothing was written. So you could continue the loop.
- For every portion that you transfer to your buffer
you send the size to the server to. That is no good. The server
will only be interested in the size of the file. So the
client should only once send a 4 bytes size.
Hans.
> const int BUFFER_SIZE = 100;
Much to small: take 5000 or more.
I copied this from a filesendclient I regularly use:
Socket->SendBuf(&size, sizeof(size));
I now see that I never check for these 4 bytes!! <g>
while(strm->Position < strm->Size)
{
int nbytes = strm->Read(buffer, MAX_BUFFER); // 5000
int n_sended = 0;
while ( n_sended < nbytes )
{
int n_sent = Socket->SendBuf(buffer + n_sended, nbytes -
n_sended );
if ( n_sent > 0 )
{
n_sended += n_sent;
ProgressBar1->StepBy ( n_sent );
}
}
Label4->Caption = "strm->Position " + IntToStr (strm->Position );
Label4->Update();
}
Hans.
Technical Details
Message-ID:
<41586b81@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<415856d5@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,b3058d6528d1daa1 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Mon, 27 Sep 2004 21:38:48 +0200 From: Hans Galema <dontusethis@dontusethis.nl> User-Agent: Mozilla Thunderbird 0.7 (Windows/20040616) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: Client: ctNonBlocking -> Server: stThreadBlocking References: <415856d5@newsgroups.borland.com> In-Reply-To: <415856d5@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 129.125.201.248 Message-ID: <41586b81@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1096313729 129.125.201.248 (27 Sep 2004 12:35:29 -0700) Lines: 63 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail