| Classification: |
C++ |
Category: |
Client-Server |
| Created: |
05/27/2008 |
Modified: |
05/29/2008 |
| Number: |
FAQ-1636 |
| Platform: |
Not Applicable |
Question:
When I send data from my client to my server synchronously the data is received properly, but after modification to asyncrhonous sending the recieved data is garbage. What might be causing this? Answer:
A possible cause of this problem would using a TBuf on the stack in the client side. This is acceptable in synchronous calls because the client-side buffer is still in scope when the message is received by the server, but it will fail for asynchronous calls if the buffer goes out of scope. The solution is to use a member variable that is guaranteed to remain in scope - for example, making the buffer a class member variable.
A more subtle form of the error would be to have a TPtr or TPtrC as a member variable, but have it point to a temporary string. The descriptor object would still be valid when the server picks it up, but the string data may be invalid. This can also happen if you pass strings from the client side using _L rather than _LIT (as _L creates a TPtrC which may go out of scope).
See also
|