[.net] Asynchronous Socket Visual Basic .Net

Started by
4 comments, last by jystic 18 years, 7 months ago
For the asynchronous socket methods in visual basic .net, what does the size parameter pertain to? For example Socket.beginreceive(data,0,5,new asynccallback(addressof Foo),0) Does this mean Foo will be called when I receive 5 bytes, that Foo will be called when I receive anywhere up to 5 bytes, and if I receive more than 5, are the others loaded into data or lost or do they wait for me to call beginreceive again? I've read that the length parameter sets the maximum length received, but I want these more specific answers because that really doesn't say much.
Advertisement
From my understanding it will receive the first 5 bytes and put it in the data variable. A common way of doing this is to limit your packet size. Example:

Dim Data As Byte(1024) ' I'm a C++ and C# programmer so I'm not to sure on the syntax. In C# it would be:

byte[] Data = new byte[1024];

So if I have Socket.BeginReceive(Data, 0, Data.Length, new asynccallback(addressof Foo), 0)

This will only receive a maximum of 1024 bytes. I hope that helps.
But if it gets less data than that will it receive the smaller ammount and expect you to check the size and call beginreceive again?
Yes that's right. I was merely stating something you can do.
Quote:Original post by Kryptus
Dim Data As Byte(1024) ' I'm a C++ and C# programmer so I'm not to sure on the syntax.
To clarify, that would contain 1025 bytes. You specify the upper bound on the array, so for a 1024 byte array you'd say Dim Data As Bytes(1023). Stupid, yes.

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

Quote:Original post by benryves
Quote:Original post by Kryptus
Dim Data As Byte(1024) ' I'm a C++ and C# programmer so I'm not to sure on the syntax.
To clarify, that would contain 1025 bytes. You specify the upper bound on the array, so for a 1024 byte array you'd say Dim Data As Bytes(1023). Stupid, yes.


Haha, that's makes no sense at all! Why did they bother making array's zero based in VB.NET if that's the case. Microsoft can be silly at times :) I can see a lot of wasted/lost single bytes in VB.NET due to people thinking the array is one based.
I've already ready slammed the plastic world through the loop to the girl in the fire. If you don't hold your colour, the sounds of life will beckon you to the terminal, by which time, you'll definately be out there.

This topic is closed to new replies.

Advertisement