how to receive a big data by socket?
how to receive a big data by socket?
i want receive a big data by socke, about 50K.
in socetReader
void CSocketsReader::RunL()
{
// Active object request complete handler
switch ( iStatus.Int() )
{
case KErrNone:
// Character has been read from socket
//TBuf8<512> iBuffer;
iEngineNotifier.ResponseReceived( iBuffer );
[COLOR="Red"] if(iBuffer'data is not enough)
{
iSocket.RecvOneOrMore( iBuffer, 0, iStatus, iDummyLength );
}[/COLOR]
break;
case KErrDisconnected:
break;
default:
break;
}
}
is it can do it ?
thanks !!
Re: how to receive a big data by socket?
In its current form it will not work (RecvOneOrMore overwrites the buffer, and SetActive is also missing). Otherwise yes, it is normal to RecvOneOrMore multiple times, and to collect the data fragments into an [I]other [/I]buffer (you can use TBuf8 if you know the desired length in build-time, but HBufC8 or CBufFlat can be useful too), until the accumulated length meets your expectations.
Re: how to receive a big data by socket?
[QUOTE=wizard_hu_;740773]In its current form it will not work (RecvOneOrMore overwrites the buffer, and SetActive is also missing). Otherwise yes, it is normal to RecvOneOrMore multiple times, and to collect the data fragments into an [I]other [/I]buffer (you can use TBuf8 if you know the desired length in build-time, but HBufC8 or CBufFlat can be useful too), until the accumulated length meets your expectations.[/QUOTE]
thanks , what is the [COLOR="Red"]iDummyLength [/COLOR] effect?
can I appoint the amount of the data, once time receive?
Re: how to receive a big data by socket?
It is a mandatory argument of RecvOneOrMore, it gives you the amount of received data. Since iBuffer.Length also tells you that, it is rarely useful. But RecvOneOrMore needs it, and it should be a member variable.
Re: how to receive a big data by socket?
[QUOTE=wizard_hu_;741044]It is a mandatory argument of RecvOneOrMore, it gives you the amount of received data. Since iBuffer.Length also tells you that, it is rarely useful. But RecvOneOrMore needs it, and it should be a member variable.[/QUOTE]
HI, wizard_hu_
my english is not enough good.
the data like
data head 1B
[COLOR="red"]date length 2B[/COLOR]
date content 5K
in my CSocketReader
int receiveLength = 0;
int totallength = 0;
TBuf[COLOR="Red"]<512>[/COLOR] iBuffer;
iBuffer.Zero(); //yh
iSocket.RecvOneOrMore ([COLOR="red"]iBuffer[/COLOR], 0, iStatus, iDummyLength);
in
void RunL()
{
if( totallength == 0 )
{
parse (iBuffer) //get totallength [COLOR="red"]by the date length 2B[/COLOR]
receiveLength = iBuffer.Length();
}
else
{
receiveLength += iBuffer.Length();
}
if(receiveLength >= totallength )
{
receiveLength = 0;
totallength = 0;
}
else
{
iSocket.RecvOneOrMore ([COLOR="red"]iBuffer[/COLOR], 0, iStatus, iDummyLength);
setActive();
}
}
by the cod can i get the all data ?
when the data is bigger than 512. i get the [COLOR="red"]by the date length 2B[/COLOR]
is not the really data length .
how can i do it .thanks!!!!!!!!!!!
Re: how to receive a big data by socket?
TBuf8<512>+RecvOneOrMore = receive [b]some[/b] (one or more, up to 512) bytes, and complete as soon as possible
TBuf8<512>+Read = receive [b]512[/b] bytes
Re: how to receive a big data by socket?
What you can do is this:[CODE]// .h
TBuf<512> iBuffer;
CBufFlat *iData;
// .cpp
RunL()
{
if(iStatus==KErrNone)
{
iData->InsertL(iData->Size(),iBuffer);
if(iData->Size()>=3) // header and length field is ready
{
TPtr8 data(iData>Ptr(0));
TUint8 head1B=data[0];
TUint16 length2B=256*data[2]+data[1];
if(iData->Size()>=length2B+3)
{
// you have the complete data in "data.Mid(3,length2B)"
}
else RecvMore();
}
else RecvMore();
}
}
RecvMore()
{
iSocket.RecvOneOrMore(iBuffer,0,iStatus,iLen);
SetActive();
}[/CODE]