Re: Help regarding MSG_PEEK



Sunil Varma wrote:
Hi,

Is there any way to find the number of bytes filled in the socket
buffer maintained by the kernel.
For suppose if a UDP server application is receiving data on some
port.
How do I know the number of bytes filled in the buffer after it
has received some data without using any recv() or recvfrom() calls.
I have to know the number of bytes in the socket buffer based on
the socket number.
You should not. Rather read what's thrown at you, and report
how much you've read. This is in most cases much more useful
that reporting what's received but not yet read by the application.

I requirement is, an appliction gives chance to open any number of
sockets(server/client).
The user can send, receive and see the statistics of the socket.
The statistics should display the total number of bytes of data
received at that point in time.
When I tried to do it with recvfrom() with MSG_PEEK, it always
shows the first received data.

calling recvfrom/recv with the MSG_PEEK flag tells you how big the next
packet to read is going to be. Then you read it (that is call recv/recvfrom without the MSG_PEEK flag.

Doing this for each packet isn't going to be very efficient. Provide
a buffer that can hold an entier udp packet, or decide on a max
packet size by other means.

.



Relevant Pages

  • Re: Fundamentals question, is this how it works?
    ... Note the packet may be partially received when you get ... That is what i thought i was saying that it receives it all in a stream ... receving the buffer size each time. ... receiving that many bytes i then break and wait for the next set of data ...
    (microsoft.public.win32.programmer.networks)
  • Re: Fundamentals question, is this how it works?
    ... Microsoft MVP, MCSD ... Knowin when that second packet started is my problem. ... stream receving the buffer size each time. ... then the receiving side might ...
    (microsoft.public.win32.programmer.networks)
  • Re: Losing UDP packets with MFC Sockets
    ... Are you saying that in the input buffer I read from ReceiveFrom could exist ... "AliR" wrote: ... > receiving process is busy doing other things. ... >> class to indicate the packet arrival. ...
    (microsoft.public.vc.mfc)
  • Re: Fundamentals question, is this how it works?
    ... You maintain a buffer for the last incomplete packet. ... receiving that many bytes i then break and wait for the next set of data ... With a tcp stream socket what happens when it is reading say 4000bytes ...
    (microsoft.public.win32.programmer.networks)
  • Re: Datagram Socket Crashes when too much data to send!
    ... Remember that calls to SendTo() don't have their data concatenated into some ... TCP socket, where there's no packetization defined; ... send buffer size (leave it at the default, ... SendToare specifying more than 1000 or so bytes (there are packet size ...
    (microsoft.public.dotnet.framework.compactframework)