Brew Question: Download Brew PDF

When transmitting large files, do we have to break the file up into packets before sending, or does BREW do this for me?

Tweet Share WhatsApp

Answer:

You should simply send what you can, and ISOCKET_Write() will tell you how much data was actually sent. If there is data remaining to be sent, simply offset your data pointer by the amount indicated by your last call to ISOCKET_Write().

For Example:

void CommonWriteCB (void *pUser) {
char *psz = NULL;
int cbWrite;
… … …

SampleApp * pMe = (SampleApp*)pUser;

// pszData is the data to be written
psz = pszData;
cbWrite = STRLEN (pszData);

// Loop till all the bytes are written.
while (cbWrite > 0) {
rv = ISOCKET_Write(pMe->m_pISocket, (byte *)psz,
(uint16)cbWrite);

if (rv == AEE_NET_WOULDBLOCK) {
// No byte were written successfully. Register
// callback to try again later.
ISOCKET_Writeable(pMe->m_pISocket,
CommonWriteCB, (void *)pMe);
return;
} else if (rv == AEE_NET_ERROR) {
// Write Error.
ReleaseNetAndSocket(pMe);
return;
}

// In case of parital write, loop and write the rest
cbWrite -= rv;
psz += rv;
}
… … …
}

Download Brew PDF Read All 78 Brew Questions
Previous QuestionNext Question
What is the largest packet size supported by BREW?How many sockets can be opened simultaneously?