receiving binary data over socket

Hi all, How should i write a routine to receive binary data on a socket (especially when there are multiple calls to recv function internally)? receiver side code while(bytesremaining) { //what should be the routine here ?(how do i copy data into buffer) bytesremaining = bytesremaining - bytesreceived; } i thought of using memcpy but then when the recv function is called second time, it will overwrite the previous written data.......so how should my code inside that while loop look? Kunal

[541 byte] By [ku19832001] at [2008-2-2]
# 1

This forum is for peer-to-peer networking questions. You can read up on using Winsock on MSDN and post questions not covered by the MSDN documentation to the microsoft.public.win32.programmer.networks newsgroup (http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.win32.programmer.networks).

The MSDN page for WSARecv in Win32 (http://msdn2.microsoft.com/en-us/library/ms741688.aspx) has a trivial example of using WSARecv to receive data from the network. If your algorithm for retrieving the data via Winsock involves reading bytes into a fixed length buffer whose size is smaller than the maximum length of your protocol's messages then at times you will be forced to copy the received bytes out of the receive buffer and into some other buffer (or use a new receive buffer) in order to reassemble your messages. I am confused as to the issue you are describing. You can use memcpy to copy the bytes out of the receive buffer and into the new buffer and then call recv/WSARecv using the old receive buffer (but this will involve more writes than simply using a new receive buffer).

If the MSDN documentation does not help please post your further questions to microsoft.public.win32.programmer.networks.

Eliot

EliotFlannery-MSFT at 2007-9-25 > top of Msdn Tech,Windows Networking Development,Peer-to-Peer Networking...