[.net] Asynchronous Socket Visual Basic .Net
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.
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.
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?
Quote:Original post by KryptusTo 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.
Dim Data As Byte(1024) ' I'm a C++ and C# programmer so I'm not to sure on the syntax.
Quote:Original post by benryvesQuote:Original post by KryptusTo 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.
Dim Data As Byte(1024) ' I'm a C++ and C# programmer so I'm not to sure on the syntax.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement