I am successfully sending messages from my Client MIDAS app to my Server
MIDAS app, but then the Client app locks up.

Here is my code:

1) The user (me) presses a button to send a message:

{ This is a test }
procedure TfClientMain.Button1Click(Sender: TObject);
begin
  SendMessageToRealTime(1, Format('%s sent at %s', [edtTestMessage.Text,
                                                    DateTimeToStr(Now)]));
end;


2) This calls a method which makes a connection, if necessary, then adds the
message to a string list. ICSSocket_Sending is a TWSocket component:

procedure TfClientMain.SendMessageToRealTime(ARecipient: Integer;
AMsgToSend: String);
begin
  if not (ICSSocket_Sending.State = wsConnected) then begin
    ICSSocket_Sending.Addr := '127.0.0.1';
    ICSSocket_Sending.Port := ClientDM.GetServerPortForClientToCall; 
    ICSSocket_Sending.Connect;
  end;
  slMessagesToSend.Add(AMsgToSend);
end;

3) I then actually send the data in the OnSessionConnected() event:

procedure TfClientMain.ICSSocket_SendingSessionConnected(Sender: TObject;
ErrCode: Word);
var
  i: Integer;
begin
  if ErrCode <> 0 then begin
    ClientDM.InsertException(CurrentUser, IntToStr(ErrCode),
      SocksErrorCodeToStr(Error));
    Exit;
  end;

  if slMessagesToSend.Count = 0 then
    Exit;

  ClientDM.InsertEventLog(
    SOCKET_EVENT, 'ICSSocket_SendingSessionConnected', Now, CurrentUser,
      GetMachineName);
  { According to Arno Garrels of TeamICS on the ICS Mailing List, the
sending
    should be done here ("Send your first bytes from OnSessionConnected") }
  for i := 0 to Pred(slMessagesToSend.Count) do
    ICS_SendString(slMessagesToSend[i]); 
  { Now get rid of them so they're not sent again }
  for i := Pred(slMessagesToSend.Count) downto 0 do
    slMessagesToSend.Delete(i);
end;

The message is getting sent (received by the Server app), but then the
Client app locks up. Why would this be?

And also: Why wouldn't the sending of the data be in the OnSendData() event?
That seems/sounds like the more logical event to send data.

The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material.  If the reader of this message is not the intended recipient,
you are hereby notified that your access is unauthorized, and any review,
dissemination, distribution or copying of this message including any
attachments is strictly prohibited.   If you are not the intended
recipient, please contact the sender and delete the material from any
computer.
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to