Fixed Sized Buffer or Variable Buffers with C# Sockets
Posted
by
Keagan Ladds
on Programmers
See other posts from Programmers
or by Keagan Ladds
Published on 2013-11-08T07:04:02Z
Indexed on
2013/11/08
10:18 UTC
Read the original article
Hit count: 288
I am busy designing a TCP Server class in C# that has events and allows the user of the class to define packets that the server can send a receive by registering a class that is derived from my "GenericPacket" class. My TCPListener uses Async methods such as .BeginReceive(..);
My issue is that because I am using the .BeginReceive(); I need to specify a buffer size when I call the function. This means I cant read the whole packet if one of my defined packets is too big. I have thought of creating a fixed sized Header that gets read using .BeginRead(); and the read the rest using Stream.Read(); but this will lead to the whole server having to wait for this operation to complete.
I would like to know if anyone has come across this before and I would appreciate any suggestions.
© Programmers or respective owner