Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question
    
This does not answer your question, but have you considered using C# 5.0 Task-based Asynchronous Pattern? It can make your code much simpler, when compared with using methods like BeginReceive(). –  svick Nov 8 '13 at 14:08
    
Also, can't you just use Stream.BeginRead() for everything? –  svick Nov 8 '13 at 14:10
    
@svick then I will have a hell of a lot of callback methods because I need one for each type of packet. –  Keagan Ladds Nov 9 '13 at 19:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.