When transmitting large files, do we have to break the file up into packets before sending, or does BREW do this for me?
Submitted by: AdministratorYou 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;
}
… … …
}
Submitted by: Administrator
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;
}
… … …
}
Submitted by: Administrator
Read Online Brew Job Interview Questions And Answers
Top Brew Questions
☺ | How to handle the case when we lose cellular coverage? |
☺ | What precautions should we take when I invoke INETMGR_GetHostByName() to perform DNS lookup? |
☺ | When reading from a socket the phone reads whatever it can in one go, while the emulator reads large packets in chunks. Why? |
☺ | Does BREW support blocking sockets? |
☺ | Why does ISHELL_CreateInstance return ECLASSNOTSUPPORT when I try and create an instance of the net manager (AEECLSID_Net)? |
Top Mobile OS Categories
☺ | iOS Interview Questions. |
☺ | Asha OS Interview Questions. |
☺ | Windows Phone (WP) Interview Questions. |
☺ | iOS Developer Interview Questions. |
☺ | BlackBerry Tablet OS Interview Questions. |