Re: send-receive using CSocket
- From: "mayara" <adolaze@xxxxxxxxx>
- Date: 29 Nov 2005 10:55:24 -0800
the image is not a constant buffer. it`s stored in a BYTE* buffer but
the dimensions are calculated when captured & they are the height&
width"for example 800*600 which is the resolution and on these basis i
send the size first& tell client to allocate memory=size.then i send
firstly a part of the image for example 32kbytes only & do a code to
make sure that the whole 32k are received & do the same at client.
i`m only sending the size before the image buffer & i`m not sending
anyother information.
take a look at send code:
tttt=(unsigned char *) buf1;//buffer containing iamge
long JTemp;
JTemp=i;
this->m_pCLSocket->Send(&i,sizeof(i));
while (JTemp>0)
{
long bsent=SendFrame((unsigned char *)tttt);
tttt+=bsent;
if(bsent>0)
JTemp-=bsent;
}
long CServerDlg::SendFrame(BYTE* buffer)
{
int retry=10;
int BytesSent;
do
{
BYTE* bp = buffer + 32000 - LeftToSend;
BytesSent = m_pCLSocket->Send( bp, LeftToSend );
LeftToSend -= BytesSent;
retry--;
if(retry<=0)
return BytesSent;
}
while ( LeftToSend>0 );
return BytesSent;
}
the client code that receives :
BYTE * CClientDlg::ReceiveBuffer()
{
//ON RECEIVE
long WSWIR=0;
this->m_pSocket->Receive(&WSWIR,sizeof(WSWIR));
int cbLeftToReceive;
BYTE * recdData = NULL;
recdData=new BYTE[32000];
cbLeftToReceive = 32000;
int iiRecd=0;
BYTE * FinalBuffer,*ptrFinalBuffer;
FinalBuffer=new BYTE[WSWIR];
ptrFinalBuffer=FinalBuffer;
long TempTotal=0;
while(WSWIR>0)
{
do
{
int iiGet;
iiGet = (cbLeftToReceive<32000) ? cbLeftToReceive : 32000 ;
iiRecd = m_pSocket->Receive( recdData+iiRecd, iiGet );
if (iiRecd!=-1)
cbLeftToReceive -= iiRecd;
WSWIR-=iiRecd;
TempTotal+=iiRecd;
}
while ( cbLeftToReceive > 0 );
memcpy(ptrFinalBuffer,recdData,TempTotal);
ptrFinalBuffer+=TempTotal;
TempTotal=0;
cbLeftToReceive = 32000;
}
.
- Follow-Ups:
- Re: send-receive using CSocket
- From: Scott McPhillips [MVP]
- Re: send-receive using CSocket
- References:
- send-receive using CSocket
- From: mayara
- Re: send-receive using CSocket
- From: Josh McFarlane
- send-receive using CSocket
- Prev by Date: Re: Drag and Drop Problem
- Next by Date: send&receive codes
- Previous by thread: Re: send-receive using CSocket
- Next by thread: Re: send-receive using CSocket
- Index(es):
Relevant Pages
|