Sign in to follow this  
Jabus10

Help with recv() in winsock

Recommended Posts

I'm quite new to using winsock and i wanted to try to use it toload the first page of my website in order to make sure i understood it well enough to do it. However when i tried to do it the recieving buffer remained empty. I wondered if you could show me in the right direction.
char buffer[256];
ZeroMemory(buffer,256);
strcpy(buffer,"GET");
MessageBox(NULL,buffer,"Test",MB_OK);
int test;
test=send(s,buffer,256,0);
if(test==SOCKET_ERROR)
{
                        
}
MessageBox(NULL,"Recieving","Test",MB_OK);
char recievingBuffer[256];
ZeroMemory(recievingBuffer,256);
MessageBox(NULL,"Recieving: Buffer has been set up","Test",MB_OK);
test=recv(s,recievingBuffer,256,0);
if(test==SOCKET_ERROR)
{
   MessageBox(NULL,"Error in Recieving","Test",MB_OK);
}
MessageBox(NULL,"Recieving: Messsage Recieved Creating MessageBox","Test",MB_OK);
MessageBox(NULL,recievingBuffer,"Verification Required",MB_OK);
MessageBox(NULL,"Recieving: Finished Recieving.","Test",MB_OK);
if(test==SOCKET_ERROR)
{
                           
}
When i first compiled it i didn't include the line ZeroMemory(recievingBuffer,256); which when the recieving buffer was displayed said Au (with accents on bothe the a and u) i then included it and now it dosen't display anything. Thank you for any help.

Share this post


Link to post
Share on other sites
I can't follow this code at all - is your message box appearing? Edit: That is, I don't see what you're trying to achieve.

BTW, using MessageBox is a dirty, dirty thing to do. Also, it blocks.

You are aware that send() blocks until recv()'d under TCP?

Beej's tutorials are a good place to start.

Share this post


Link to post
Share on other sites
Quote:
You are aware that send() blocks until recv()'d under TCP?


This is not true, unless the TCP window is entirely full (i e, the receiving and sending side buffers are completely full).


I can see three problems with the code snippets:

1) Use breakpoints in the debugger instead of MessageBox. They are easier to add/remove, and don't require re-compiles to change.

2) You're sending the entire 256 bytes, even though the string is only 4 bytes ("GET" plus terminator).

3) You're trying to receive on the same socket -- what is the socket connected to, and are you sure that the other end is sending something in reply?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this