Hello Helge,
I appreciate the reply and you taking your time to read my post. Please read
inline:
"Helge Jensen" wrote:
>
>
> Michael--J wrote:
>
> > I have been writing a Communications protocol component in C# that will
>
> Instead of implementing your own solution, you could use remoting.
>
Yes you are correct, I could have used remoting. I would really love to use
that technology because it would definitely take a huge burden off my
shoulders. Our component however, is being designed so that it can be used in
PC applications that run under the .NET Framework (Full) environment, as well
as embedded applications (that run on embedded devices with Windows CE 5.0)
that only run in the .NET Compact Framework environment. And since the
Compact Framework does not support .NET Remoting, I could not go down that
path.
> > - On receiving, bytes are received asynchronously by calling the Socket
> > object's BeginReceive() and EndReceive() methods. The receiving process
>
> Avoid async-IO unless absolutely forced to do it. It is *very*
> complicated to get right -- really!
>
Yeah right?!! Is Async-IO really that difficult? If I only knew that
earlier, I may have resorted to sych methods only.
> > Everytime the client app receives an packet, it prints out the contents on a
> > RichTextBox and then clears it for the next packet. So visually, the client's
> > RichTextBox blinks with the contents of received packets. When i have this in
> > the code, it works fine. However, if i comment out the section that prints
> > the packet contents (so the RichTextBox will always be blank), something
> > bizarre occurs:
>
> Timing influences the way multi-threaded and asynchroneus programs work.
> Try making a *very* small example program and do your tests on that,
> so you can understand what's going on.
>
> You can try insert some Thread.Sleep(0) in order to try and provoke some
> timing errors by having the threads rescheduled.
>
Yes you are right, timing does play a great deal in this component. I
noticed that putting a Thread.Sleep(80) in place of the code that prints out
packet contents on the client app’s RichTextBox, made system run fine.
However, putting a Thread.Sleep(20) did not. If I change my implementation to
a synch-IO approach, will that help make things run better? Guaranteed? Or
will I still get timing issues?
The example programs i have written, i thought, seem small. They are
basically a server and client that play "packet tennis". I need to be able to
stress test the server with about 500 connected clients all playing packet
tennis. When you said *very* small program, what type of program do you mean?
> > packet sizes being received are all 2KB. What is going on here??
>
> Could easily be a synchronization bug in your async-IO. It's *very* hard
> to get async I/O right.
>
That is really a shame. Thanks for the heads up. I think another issue that
may cause problems is the resending. When i have about 100 clients connected
the server maybe struggling to keep up with them, and each client resends
packets at an interval of 200ms (RTO). Maybe the high influx of packets
corrupts the streams or something?? I was thinking of increasing the RTO to
about 1 sec and see how that goes. I might give that a try.
> Are you allowed to read and write to the Socket from multiple treads at
> once? I suspect not. Perhaps writing the ACK to the socket moves a
> pointer in the Socket's buffer -- which would explain the behaviour you
> are experiencing.
>
Yes i think you are allowed to read and write to the Socket from multiple
threads. I mean, that's exactly what i'm doing. The sending process is
totally separate from the receiving process but they both access the same
Socket. Maybe that observation could be the key... hmm... Maybe that is why i
am experiencing the behaviour i mentioned... you could be on the right track
Helge...
> > Please excuse the lengthy post. I needed to explain how my component worked
> > for easier analysis on your behalf. Thanks in advance.
>
> I would guess that most of the content of the post is unrelated to your
> problem.
>
> BTW1: I don't really understand why you are using async IO for reading
> the input. you could just as well use sync, with exactly the same result.
>
The only reason why i used asych IO was simply because it made things
"easier" and there was no blocking taking place. Using sych IO will give
exactly the same result? Including the timing issues? I hope not - i may give
it a try...
> BTW2: Are you certain you will always receive 1 full packet per read of
> the Socket?
>
No. As a matter of fact there are instances where i only receive a portion
of the packet at a time. I have actually taken this into account in my code
and tested it with dummy packets as well. The behaviour i was telling you
about where the packets sizes decrease (and hence show up as incomplete
packets) get processed in that portion of the code - but the thing is i dont
know whether their remaining bytes get received or not.
> --
> Helge Jensen
> private.php?do=newpm&u=
> sip:(E-Mail Removed)
> -=> Sebastian cover-music: http://ungdomshus.nu <=-
>