Winsock - Empty Receiving Buffer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ramiro Barbosa, Jr.

    Winsock - Empty Receiving Buffer

    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(receiv ingSocket,szMes sage,sizeof(szM essage),0,socka ddr*)&addr_Cli,
    &clilen);

    Any ideas?

    Thank you and regards!

    -Ramiro
  • Victor Bazarov

    #2
    Re: Winsock - Empty Receiving Buffer

    "Ramiro Barbosa, Jr." <ramiro_b@yahoo .com> wrote...[color=blue]
    > 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(receiv ingSocket,szMes sage,sizeof(szM essage),0,socka ddr*)&addr_Cli,
    > &clilen);
    >
    > Any ideas?[/color]

    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


    Comment

    • Ramiro Barbosa, Jr.

      #3
      Re: Winsock - Empty Receiving Buffer

      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(receiv ingSocket,szMes sage,sizeof(szM essage),0,(sock addr*)&addr_Cli ,&clilen);

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

      Regards,

      -Ramiro


      "Victor Bazarov" <v.Abazarov@com Acast.net> wrote in message news:<RU_cd.273 151$D%.236125@a ttbi_s51>...[color=blue]
      > "Ramiro Barbosa, Jr." <ramiro_b@yahoo .com> wrote...[color=green]
      > > 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(receiv ingSocket,szMes sage,sizeof(szM essage),0,socka ddr*)&addr_Cli,
      > > &clilen);
      > >
      > > Any ideas?[/color]
      >
      > 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[/color]

      Comment

      • Victor Bazarov

        #4
        Re: Winsock - Empty Receiving Buffer

        Ramiro Barbosa, Jr. wrote:[color=blue]
        > 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(receiv ingSocket,szMes sage,sizeof(szM essage),0,(sock addr*)&addr_Cli ,&clilen);
        >
        > Previously, I made a mistake cutting/pasting it here.[/color]

        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.

        Comment

        • Ramiro Barbosa, Jr.

          #5
          Re: Winsock - Empty Receiving Buffer

          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
          ["<<szMessag e[i]<<"]"<<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 <v.Abazarov@com Acast.net> wrote in message news:<3V8dd.590 3$Ae.1299@newsr ead1.dllstx09.u s.to.verio.net> ...[color=blue]
          > Ramiro Barbosa, Jr. wrote:[color=green]
          > > 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(receiv ingSocket,szMes sage,sizeof(szM essage),0,(sock addr*)&addr_Cli ,&clilen);
          > >
          > > Previously, I made a mistake cutting/pasting it here.[/color]
          >
          > 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.[/color]

          Comment

          Working...