Thread View: borland.public.cppbuilder.internet.socket
4 messages
4 total messages
Started by Fabi�n
Mon, 05 Jul 2004 17:37
Send a jpeg
Author: Fabi�n
Date: Mon, 05 Jul 2004 17:37
Date: Mon, 05 Jul 2004 17:37
4 lines
1051 bytes
1051 bytes
Hi! I'm trying to transfer a jpeg. I have problems using a stream. Is there a better method?
Re: Send a jpeg
Author: Remy Lebeau (TeamB)
Date: Mon, 05 Jul 2004 18:11
Date: Mon, 05 Jul 2004 18:11
12 lines
1144 bytes
1144 bytes
"Fabi�n" <fabianfierro@hotmail.com> wrote in message news:40e99192$1@newsgroups.borland.com... > I'm trying to transfer a jpeg. > I have problems using a stream. Can you be more specific please? What exactly are you having a problem with? Gambit
Re: Send a jpeg
Author: Fabi�n
Date: Tue, 06 Jul 2004 14:07
Date: Tue, 06 Jul 2004 14:07
85 lines
3155 bytes
3155 bytes
I send the file in parts. Then I join them again. But i doesn't work. I
think I did it too simple
here is my code:
BYTE tBuffer[100];
TJPEGImage *tjp = new TJPEGImage();
TMemoryStream* tpms = new TMemoryStream();
//--------------------------------------------------------------------------
-
void __fastcall TfMain::wmImagenClick(TObject *Sender)
{
BYTE Buffer[100];
int pos = 0;
OpenPictureDialog->FileName = GraphicFileMask(__classid(TJPEGImage));
if (OpenPictureDialog->Execute())
{
TJPEGImage *jp = new TJPEGImage();
TMemoryStream* pms = new TMemoryStream();
jp->LoadFromFile(OpenPictureDialog->FileName);
jp->SaveToStream(pms);
while(pos < pms->Size - 100)
{
pms->Seek(pos, soFromBeginning);
pms->ReadBuffer(Buffer, 100);
ClientSocket->Socket->SendBuf(Buffer, 100);
pos += 100;
}
pms->Seek(pos, soFromBeginning);
pms->ReadBuffer(Buffer, pms->Size - pos);
ClientSocket->Socket->SendBuf(Buffer, pms->Size - pos);
}
}
//--------------------------------------------------------------------------
-
void __fastcall TfMain::ServerSocketClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
int total = Socket->ReceiveLength(), recived, newpacketsize;
recived = tpms->Size;
if(total - recived > 100)
newpacketsize = 100;
else
newpacketsize = total - recived;
Socket->ReceiveBuf(tBuffer, newpacketsize);
tpms->WriteBuffer(tBuffer, newpacketsize);
if(tpms->Size == total)
{
tjp->LoadFromStream(tpms);
PaintBox->Canvas->Draw(0,0,tjp);
}
}
//--------------------------------------------------------------------------
-
"Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> escribi� en el
mensaje news:40e99afa$1@newsgroups.borland.com...
>
> "Fabi�n" <fabianfierro@hotmail.com> wrote in message
> news:40e99192$1@newsgroups.borland.com...
>
> > I'm trying to transfer a jpeg.
> > I have problems using a stream.
>
> Can you be more specific please? What exactly are you having a problem
> with?
>
>
> Gambit
>
>
Re: Send a jpeg
Author: 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads