DelphiBuilder / NetCom7

The fastest communications possible. Delphi rulez.
MIT License
174 stars 43 forks source link

Received client message string repeated within the same message #23

Closed mrandreastoth closed 6 months ago

mrandreastoth commented 2 years ago

Commit 50205fcf0e691853027db437d6d04fa65b504497 introduces a simple manual client/server test program.

Issue

The test program fails when executing client sends in rapid succession, i.e., when hitting "Send from clients" multiple times in a row in which case some received messages appear as containing duplicated strings of the original message.

Steps to reproduce

  1. Run ClientServerTest (only tested under Windows 10)
  2. Click "Toggle server"
  3. Click the spin edit up button until the number 6 is displayed
  4. Click "Add clients"
  5. Rapidly click on of the "Send from clients" button a few times in succession

Observed behaviour

Some messages are flagged as CORRUPT. On inspecting any of these messages it can be seen that the reason for the message having been flagged is that the original message string has been repeated within the same message.

Expected behaviour

No messages are flagged as CORRUPT.

Note

This issue may be related to #20.

mrandreastoth commented 2 years ago

The following is the edited output from a test run with six (6) clients where I rapidly click on both the "Send to clients" and "Send from clients" buttons. Note the client messages flagged as CORRUPT...

Server created Client0 created Client1 created Client2 created Client3 created Client4 created Client5 created ServerClient0 created ServerClient1 created ServerClient2 created ServerClient3 created ServerClient4 created ServerClient5 created ... Client0 sent data to Server (Data = ) Client1 sent data to Server (Data = ) Client2 sent data to Server (Data = ) Client3 sent data to Server (Data = ) Client4 sent data to Server (Data = ) Client5 sent data to Server (Data = ) Server received data from Client0 (Data = ) Client0 sent data to Server (Data = ) Client1 sent data to Server (Data = ) Client2 sent data to Server (Data = ) Client3 sent data to Server (Data = ) Client4 sent data to Server (Data = ) Client5 sent data to Server (Data = ) Server received data from Client1 (Data = ) Server received data from Client2 (Data = ) <<< CORRUPT >>> Server received data from Client3 (Data = ) <<< CORRUPT >>> Server received data from Client4 (Data = ) <<< CORRUPT >>> Server received data from Client5 (Data = ) <<< CORRUPT >>> Server received data from Client0 (Data = ) Server received data from Client1 (Data = ) ...

mrandreastoth commented 2 years ago

The latest commit to my fork, i.e., 8bb318f, resolves the issue. However, it doesn't seem right. Surely the read buffer should be flushed on each read instead of being appended to even if multiple reads occur to Readable???

DelphiBuilder commented 6 months ago

Hi there, sorry for such a late reply. The buffer DOES NOT change length every time you may be in the OnHandle event. This is for PERFORMANCE. In order to get the byte count you have received, you have to see the parameter giving you the Count.