Help with recv() in winsock

Started by
1 comment, last by hplus0603 17 years, 7 months ago
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.
Advertisement
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.
Winterdyne Solutions Ltd is recruiting - this thread for details!
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?
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement