I've implemented a TWSocket client using a state machine, but after I send the data using SendStr(), the OnDataSent() event gets fired twice. I've confirmed that the data I'm sending is being put into a single buffer (it's 527 bytes), so I don't understand why the OnDataSent() method is being called twice.
I've searched the ICS mailing list, but none of the posts I found so far answered this question specifically, other than to say that OnDataSent() is fired when the buffer is emptied, which is why I'm confused that I'd see it twice in this scenario (and I've confirmed with breakpoints that I'm only calling SendStr() once in the OnConnect event). Is this expected behavior? Thanks, Doug Pseudo code: procedure TMyClient.OnConnect(); begin FClientState := csSendingData; FSocket.SendStr(MyString); end; procedure TMyClient.OnDataSent(Sender: TObject; Error: Word); begin Assert(FClientState = csSendingData); <========== FAILS HERE SECOND TIME (because FClientState was set to csWaitingForResponse the first time) ************************* // buffered data has been sent, so wait for response FClientState := csWaitingForResponse; // set some other internal variables end; procedure TMyClient.OnDataAvailable(Sender: TObject; Error: Word); begin Assert(FClientState = csWaitingForResponse); MyReceivedData := FSocket.ReceiveStr; // do something with the data (e.g., post to a queue) end; procedure TMyClient.WaitUntilQuit; begin FSocket.MessageLoop; end; // pseudo code to initiate connection procedure DoSendRequest; var MyClient: TMyClient; begin MyClient := TMyClient.Create; MyClient.Connect; MyClient.WaitUntilQuit; end; -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be