Re: send-receive using CSocket



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;
}

.



Relevant Pages

  • Re: Socket write behaviour is inconsistent?
    ... copy 1 byte to buffer, copy many bytes to buffer, copy one byte to ... Then why did you write "the client throws an error"? ... remote endpoint for your connection. ... When the response is sent using the first chunk of code, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: TCPClient Synchronous or Asynchronous Writes
    ... acting as the "server" receives quality assurance data from different ... Each client can register to look at differnt data so there ... is actually a Circular Buffer for each client. ... >> stream data to my clients over a TCPClient connection. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: NIO best practice
    ... ByteBuffer buffer) { ... SelectionKey key=client.keyFor; ... ChannelState state=selkey.attachment; ... transfer_file(selkey, client, state); ...
    (comp.lang.java.programmer)
  • Re: USB data Transfer question
    ... I'm afraid you can't pass 1-byte length buffer ... the pBuffer!=0 if there is data sending from client. ... and both USB analizer and the pBuffer value is the ... and the write function which write data from USB host to client works ...
    (microsoft.public.windowsce.platbuilder)
  • Re: TCPClient Synchronous or Asynchronous Writes
    ... there's no guarantee the first packet of data ... post it off to the client every few seconds in one block. ... > stream data to my clients over a TCPClient connection. ... > On the server I have a custom circular data buffer that receives byte ...
    (microsoft.public.dotnet.languages.csharp)