Buffers

mmiers

Newcomer
Joined
Apr 3, 2003
Messages
7
<alliteration>Buffers are baffling to me.</alliteration>

I understand the concept of buffers. You put data into a buffer, send it to the recipient, that data goes into a buffer, the data is read from it.

Now then, it's rather difficult to explain my question. I know how to use buffers, but I'd like to know more. :D

I've read countless articles on vb.net networking, most by microsoft, but some questions remain. Here are some specific questions maybe someone can answer for me.

Why does the buffersize matter? If the size is to large, will vb attempt to send all of the data at once or split it up? I've heard reccommended buffer sizes of about 2K up to even 32K !

If data is split up at all when transfering, when vb says i've received data, is it all of the data that the client originally sent, or just what it's received so far?


In microsoft's example of a chat app, the receiver waited for a line feed before processing. However, I couldn't tell if the sender was manually splitting up these chunks or if it sent the whole line using send, then vb split the data up.

Hopefully you can see what area of buffering I have some confusion about by these two questions. Basically, I'd like to know all of what vb.net is doing behind the scenes when I'm sending and receiving.

Please, answers to these specific questions along with any resources would be greatly appreciated.

Thanks
- Mark
 
Right when transfering data, you tend to send it out in packets that why you split the data up I tend to use a packet size of around 512 bytes (Split the file or data into 512 byte chunks) each packet is sent until all of it has been sent

i.e
1mb FILE = 1048576 bytes
1048576 bytes = 2048 packets (1048576 / 512)

So in this example I would send 2048 packets to the other computer before all the has been sent. That means 2048 packets would have to be received by the computer before it has the complete 1mb file.

As the recieving computer gets these packets it Buffers them normally buffers the results then normaly you immediatly write them to file using Streams.

For Chat not like MSN

You send a string with as you say in the microsoft example with the line feed char, the recieving computer will Buffer this string until the line feed (or any charater you choose) is received then you put all the contents of the buffer to screen and empty the buffer.

e.g.

Send 2 packet as below

PACKET1 = "This is my first packet"
PACKET2 = "This is my second packet" + LINEFEED

The receiving computer will receive the first packet then because there was no LINEFEED add the second packet to the end of the first, because there was a line feed on the second packet you are effectivally saying thats all the data and do somthing.

NOTE: You make the rules for packets sending data and what to do when you receive it i.e PROTOCOL


Hope this give you a bit more of an idea but this is the simplest way I could explain

Andy
 
Thanks for the grammatically interesting reply. :)

I got the jist though. The receiving buffer is 2 parts, the one read into by vb when receiving data, and a second used to wait for a full line of information.

That's very helpful. Many examples use streams but I never really looked into them. I'll take a look now though.

Another follow up question. What would happen if the buffer is set to large? To small? I believe the to small is obvious. There would be a large amount of processing on many many packets.

Thanks again
- Mark
 
Back
Top