Hi!

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 ?
Thanks

Recommended Answers

All 3 Replies

>Dynamic buffer size for socket ?

Take a look at this thread.

commented: Best wishes to you and your family also :) +8

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?

Thanks

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"))
                bw.Write(coming);
            }
            bw.Close();
            fs.Close();

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)
                    --i;
                // 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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.