There is anyway to make the buffer size of a socket dynamic ?
Because i need to download some things and my buffer of 1024 bytes cant get all the information.
How could i do this ?

6 Years
Discussion Span
Last Post by krosty4782
Featured Replies
  • 1
    __avd 1,826   6 Years Ago

    >Dynamic buffer size for socket ? Take a look at [URL="http://stackoverflow.com/questions/2811006/what-is-a-good-buffer-size-for-socket-programming"]this[/URL] thread. Read More


>Dynamic buffer size for socket ?

Take a look at this thread.

Votes + Comments
Best wishes to you and your family also :)

So you say to do a while loop, to receive all the data in more than one step ?
I have tried that, but i have two problems the one is that i don't know how to properly safe the temp buffer and then join with the other buffer that are received.
Suppouse, i send a data that is read in 5 times by mu buffer.
How could i save the 5 parts (in bytes) and join them propertly ?
And the other thing is, that i don't know when to stop the while loop.
If i send 3mb data, how do i know when all data is received and stop the loop?



I have been trying but without success.
I have this code:

while (!String.Equals(opasgard, "opasgarfinish"))
                coming = getSocket(numsock).receiveDownload();
                opasgard = encoding.GetString(coming);
                if(!String.Equals(opasgard, "opasgarfinish"))

And the receive function:

public byte[] receiveDownload()
                buffer = new byte[13];
                string[] words;
                len = socket.Receive(buffer);
                i = (buffer.Length) - 1;
                while (buffer[i] == 0)
                // now bar[i] is the last non-zero byte
                bar = new byte[i + 1];                           
                words = System.Text.Encoding.UTF8.GetString(bar).Split('|');                
                if (words.Contains("opasgarfinish"))
                    System.Text.ASCIIEncoding  encoding=new System.Text.ASCIIEncoding();
                    Byte[] opasgard = encoding.GetBytes("opasgarfinish");
                    return opasgard;
                return bar;   

And the file is made, but now with the correct chars, i get:

**You have 敲挀攀椀瘀攀搀 琀栀攀 猀oftware as p牡琀 漀昀 琀栀攀 嘀椀猀ual Studio 9〮 䈀攀琀愀 倀爀漀最爀愀m.

When it must be:

**You have received the software as part of the Visual Studio 9.0 Beta Program.

Any idea?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.