Winsock - Empty Receiving Buffer

  • Thread starter Ramiro Barbosa, Jr.
  • Start date
R

Ramiro Barbosa, Jr.

All,

In regards to the call below, I was wondering why is it that the
'szMessage' receiving buffer results in an empty one, but by printing
'ret' it indicates the number of bytes I am indeed receiving!

int ret = recvfrom(receivingSocket,szMessage,sizeof(szMessage),0,sockaddr*)&addr_Cli,
&clilen);

Any ideas?

Thank you and regards!

-Ramiro
 
V

Victor Bazarov

Ramiro Barbosa said:
In regards to the call below, I was wondering why is it that the
'szMessage' receiving buffer results in an empty one, but by printing
'ret' it indicates the number of bytes I am indeed receiving!

int ret =
recvfrom(receivingSocket,szMessage,sizeof(szMessage),0,sockaddr*)&addr_Cli,
&clilen);

Any ideas?

Too many unknowns here. First of all, 'recvfrom' is not a standard C++
function, so you should _strongly_ consider posting to a newsgroup where
it's topical (like the NG for your platform). Second, what do you mean
by "receiving buffer results in an empty one"? If the function indicates
that it received something, then your buffer must contain something.
How else can you conclude that it's empty? Since you didn't show what
is the "buffer" you're talking about, or how it's declared, there is no
way to conclude that you're using the correct method of understanding
whether it contains anything.

V
 
R

Ramiro Barbosa, Jr.

Victor,

Thanks for the reply! In the Winsock function 'recvfrom', the
receiving buffer can only be the second parameter (szMessage). What I
meant was, why my 'szMessage' parameter is empty after the call and
the 'ret' variable is populated w/ the correct number of bytes. I ran
it through the debugger and it is indeed empty! The szMessage is
declared as "char szMessage[65535];" The call should read...

int ret = recvfrom(receivingSocket,szMessage,sizeof(szMessage),0,(sockaddr*)&addr_Cli,&clilen);

Previously, I made a mistake cutting/pasting it here.

Regards,

-Ramiro
 
V

Victor Bazarov

Ramiro said:
Victor,

Thanks for the reply! In the Winsock function 'recvfrom', the
receiving buffer can only be the second parameter (szMessage). What I
meant was, why my 'szMessage' parameter is empty after the call and
the 'ret' variable is populated w/ the correct number of bytes. I ran
it through the debugger and it is indeed empty! The szMessage is
declared as "char szMessage[65535];" The call should read...

int ret = recvfrom(receivingSocket,szMessage,sizeof(szMessage),0,(sockaddr*)&addr_Cli,&clilen);

Previously, I made a mistake cutting/pasting it here.

Ramiro,

What does it mean "empty"? You keep saying that the buffer is empty,
yet it at the time of definition it already contains 65535 characters.
They have random values, yes, but it's not _empty_. If the function
specification tells you that the return value is the number of bytes
received, it means they were received. Do you not trust the people
who made the function? What other reason do you have to believe that
the bytes have _not_ been received?

Think about it for a bit before replying.

V

P.S. An example of an "empty" container is a standard vector, std::vector
object, right after being default-initialised or right after clearing. We
can confirm that it's "empty" by calling the member function 'empty()' for
it, which will return 'true'. For character arrays there must be some
other way of judging that it's "empty". You still didn't say what your
method is.
 
R

Ramiro Barbosa, Jr.

Hi Victor,

Yes, you're correct! I initially placed 65535 random characters into
that memory space, so the array is not empty at all. My idea of empty
came from trying to cout<<szMessage<<endl which didn't display
anything and made me believe it was empty (not having the bytes
returned by the function) array! Thanks for making me think in the
right direction. Now I can actually iterate the array and access it
such as... for(int i = 0; i<65535; i++) cout<<"Contents
["<<szMessage<<"]"<<endl; if I want and display its contents. I
guess now I have to believe the makers of that function, uh?

Thanks a lot, and regards,

-Ramiro



Victor Bazarov said:
Ramiro said:
Victor,

Thanks for the reply! In the Winsock function 'recvfrom', the
receiving buffer can only be the second parameter (szMessage). What I
meant was, why my 'szMessage' parameter is empty after the call and
the 'ret' variable is populated w/ the correct number of bytes. I ran
it through the debugger and it is indeed empty! The szMessage is
declared as "char szMessage[65535];" The call should read...

int ret = recvfrom(receivingSocket,szMessage,sizeof(szMessage),0,(sockaddr*)&addr_Cli,&clilen);

Previously, I made a mistake cutting/pasting it here.

Ramiro,

What does it mean "empty"? You keep saying that the buffer is empty,
yet it at the time of definition it already contains 65535 characters.
They have random values, yes, but it's not _empty_. If the function
specification tells you that the return value is the number of bytes
received, it means they were received. Do you not trust the people
who made the function? What other reason do you have to believe that
the bytes have _not_ been received?

Think about it for a bit before replying.

V

P.S. An example of an "empty" container is a standard vector, std::vector
object, right after being default-initialised or right after clearing. We
can confirm that it's "empty" by calling the member function 'empty()' for
it, which will return 'true'. For character arrays there must be some
other way of judging that it's "empty". You still didn't say what your
method is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top