Skip to main content
GameDev.net gamedev.net
🔒 Locked

Data Format via CString and/or string :: Winsock

Started by kuphryn Nov 3, 2002 at 3:20 PM 1 replies 500+ views
Original Post
kuphryn
kuphryn
Hi. I am implementing an overlapped I/O based Winsock program. I would like to know how to format the data buffer after WSARecv returns. For example: ----- // Allocate 100 bytes. TCHAR *data = new data[100 + 1]; data[100] = NULL; // Link data buffer and size to WSABUF. WSABUF wBuf; wBuf.len = 10000; wBuf.buf = data; ... WSARecv(..., &wBuf,...,); ... ----- Given WSARecv returns after sometime with the data, how do you format, 20 bytes of valid data. In other words, data could contain 100 bytes of data, however, what if only 20 bytes are valid and the rest are random data Winsock produces from the socket? I tried using CString and trim(), but it does not seem to help under an overlapped I/O. For example: ----- WSARecv(...); ... CString validData = CString(data); validData.trim(); ----- The solution above does not work for overlapped I/O. Even with trim(), validData will hold some valid data and a whole lot of random bytes. I would like to know how to format a raw byte data buffer into valid characters only. Thanks, Kuphryn
niyaw
niyaw
all send/receive functions return the number of bytes actually transfered. it will be in lpNumberOfBytesRecvd for WSARecv, in lpcbTransfer for WSAGetOverlappedResult, and in cbTransfered parameter to your completion routine. that number tells you how much of receive buffer is actually filled with valid data.
kuphryn
kuphryn
Nice! Good tip. Thanks.

Kuphryn

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.