Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Socket- recv();

Status
Not open for further replies.

ForeverCode

Programmer
Dec 6, 2002
41
US
char Read[1000];

recv(Socket, Read, 1000, NULL);

That puts the clients sent data into Read, but what if the data being sent is greater than the size of the buffer? How would I check to see if I have recieved all the data, and if not read the rest? I can't figure out the best way to do this:/ Any suggestions?
 
Also, you can specify a larger buffer to be on the safe side. Allowing 10,000 bytes rather than 1,000 is not a big deal in terms of memory usage. However, if you are communicating with a server (especially one which you know the protocols - possibly because you wrote it) then you should know the pre-set limits of buffer size limits within which you can work safely.
In addition, if you work with UDP sockets rather than STREAM sockets then you should try to keep the buffer (and therefore the packages) as small as possible.
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
Alright, thanx. This is for a web server I'm writting. The problem was that if someone sends a million and a half GET variables the protocol doesn't tell how long the data being sent is.

ex:

GET /index.php?stuff=fdslkadfsalkfsad%20klfjdslkajfdslkajfdsajflsdajklfdjaslkfjdslakjfdlksajlk;dfs&this=fdlkafjsqhfjsdahfklsdjlkfjdslkajlk;sdjalkfdjsalkfdsa...
Host:
But, if the client posts data then it will tell me how long it will be. It's just the GET data that gives me the trouble.
 
Don't you get the length of the GET request by examing the CONTENT_LENGTH variable????
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
No, not from the clients request. The server is suppose to figure it out itself...Only with POST does the client send the length of the data. I need to do some more reading up on the HTTP protocol but hopefully there is a limit on the size of a request unless the size is specified.
 
Ahhh! I see what you mean! Normally with GET methods the content length is stored in the appropriate environmental variable which can be retrieved using the [tt]getenv()[/tt] function. Have you done a search on the web for this information - it should be publicly documented and freely available.
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
[the code is not syntactically correct, it just illustrates an idea that u can use in your code].

You can read the socket in a loop like this
string get_request;
while ((numRead = recv(SOCKET, buf, 1000, MSG_DONTWAIT)) != 0)
{
if (numRead < 0)
{
// error occured.
// break out of the loop with an exception
}

get_request.append(buf, numRead); // i.e. append however many bytes have been read.

// sleep for 100 ms [this can be a configurable variable]
}

// at this point if all goes well u will have your GET request in the get_request variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top