Article View: borland.public.cppbuilder.internet.socket
Article #5688Re: Send a jpeg
From: Remy Lebeau (TeamB)
Date: Tue, 06 Jul 2004 18:05
Date: Tue, 06 Jul 2004 18:05
30 lines
2490 bytes
2490 bytes
"Fabi�n" <fabianfierro@hotmail.com> wrote in message news:40eab37b$1@newsgroups.borland.com... > I send the file in parts. Then I join them again. But i > doesn't work. I think I did it too simple On the client side, are you using the TClientSocket in blocking or non-blocking mode? 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. On the server side, you are assuming that the entire data stream will be available in full every time the OnClientRead event is triggered. That is not correct. The OnClientRead event is triggered whenever *any* data arrives, even just 1 byte. It is very common and likely that OnClientRead will be triggered multiple times while you transferring a single data stream. It is your responsibility to buffer all of the incoming data until the entire stream is received in full, and only then process the buffered data as a whole. In order to do that, though, you need to know how many bytes to expect from the stream so that you can know when you have finally received all of the data. You should send the stream's Size before sending the actual stream data. Then the server can read the Size and know how many additional bytes to expect. Gambit
Technical Details
Message-ID:
<40eae9dc$1@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:
<40e99192$1@newsgroups.borland.com> <40e99afa$1@newsgroups.borland.com> <40eab37b$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,bae0299eb0ad2238 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <40e99192$1@newsgroups.borland.com> <40e99afa$1@newsgroups.borland.com> <40eab37b$1@newsgroups.borland.com> Subject: Re: Send a jpeg Date: Tue, 6 Jul 2004 11:05:37 -0700 Lines: 32 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.10 Message-ID: <40eae9dc$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1089137116 68.69.17.10 (6 Jul 2004 11:05:16 -0700) 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