Results 1 to 4 of 4

Thread: Sockets - receiving a large buffer?

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Sockets - receiving a large buffer?

    (First time trying to do socket programming )
    I'm trying to read a large buffer using sockets. Is there anything wrong with this psudo code?

    Code:
    DO
      mySocket.Receive(buff)   ' temporary buffer, discard the data
    WHILE (mySocket.Available > 0)

    it terminates after the first iteration because, I suppose, it reads the data faster than the sender is sending it, and Socket.Available will be 0 (if i break the debugger and step through it, it receives the whole buffer). How can i make the Receive call block until more data is available? (I've tried setting Socket.ReceiveTimeout, but it doesn't seem to do any good)
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Sockets - receiving a large buffer?

    The Receive method will read all data available. If no data is available it will block until data is available.

    It all boils down to what it is you're reading from the stream and why. If you need to be reading from the stream continously, and "endless" loop is the normal approach:
    Code:
    Do
     mySocket.Receive(buff)
     ' Do some more work with the received data
    While True
    Altough if that is not the case, you would have to know when you have received all of it. Since you're the only one that knows what it is you're receiving, do you have anything that could tell you when you've received all data?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Sockets - receiving a large buffer?

    no.... no indication of when i've received the whole buffer

    see, on the server side I'm sending the data in small buffers (using unix sockets), so a call to Receive from the .NET client app might return after reading that chunk of data, and think that no more data is available.....

    so is there no elegant way of making the Receive() call wait until more data is available? if not i guess I'll stick with the infinite loop
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Sockets - receiving a large buffer?

    Quote Originally Posted by MrPolite View Post
    ..
    so is there no elegant way of making the Receive() call wait until more data is available? ...
    Well...thats actually what Receive does if you call it when no more data is available. If on the other hand, data is available when you call Receive, it'll return that data to you. What I believe you're asking for would require the socket to know that more data is on its way (and wait for it to arrive, THEN return the data to you), which it cant
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width