Hello again (after a long absence). I am using Delphi 2006 and the ICS TWSocket and TWSocketServer components, in a MIDAS app.
Is it possible to send messages from my client app to my server app on the same machine (they are both running on the same machine during development/testing)? I would assume so, but it's not working. Specifically, the server app's ClientConnect() event is not firing. This is where the OnDataAvailable() event is hooked up. Since ClientConnect() does not fire, the Server never "gets" the message sent. Here is the pertinent code: CLIENT APP: Sending the message to the Server app running on the same machine: if not (ICSSocket_Sending.State = wsConnected) then begin { Not connected yet, start connection } ICSSocket_Sending.Addr := '127.0.0.1'; ICSSocket_Sending.Port := 42; ICSSocket_Sending.Connect; end; ICS_SendString('Bla bla bla'); SERVER APP: 1a). {--------------------------------------------------------------------------- ---} procedure TfJCPServer.FormShow(Sender: TObject); begin PostMessage(Handle, WM_APPSTARTUP, 0, 0); end; 1b). Set port to listen to: {--------------------------------------------------------------------------- ---} procedure TfJCPServer.WMAppStartup(var Msg: TMessage); begin { Listen to messages from the Client app } ICSSocketServer_Listening_ClientApp.Port := 42; ICSSocketServer_Listening_ClientApp.Addr := '0.0.0.0'; { Use any interface } { This prevents the typecasts from failing } ICSSocketServer_Listening_ClientApp.ClientClass := TTcpSrvClient; { Use our component } ICSSocketServer_Listening_ClientApp.Listen; { Start listening } end; 2. ClientConnect() event handler: procedure TfJCPServer.ICSSocketServer_Listening_ClientAppClientConnect(Sender: TObject; Client: TWSocketClient; Error: Word); begin if Error <> 0 then begin InsertIntoExceptionLog( CurrentUser, GetMachineName, SocksErrorCodeToStr(Error), IntToStr(Error)); Exit; end; InsertEventLog(SOCKET_EVENT, 'ICSSocketServer_Listening_ClientAppClientConnect'); with Client as TTcpSrvClient do begin LineMode := True; LineEdit := True; LineLimit := 255; { Do not accept long lines } //changed from 80 OnDataAvailable := ClientDataAvailable_ClientApp; OnLineLimitExceeded := ClientLineLimitExceeded_ClientApp; OnBgException := ClientBgException_ClientApp; ConnectTime := Now; end; end; 3. OnDataAvailable(): procedure TfJCPServer.ClientDataAvailable_ClientApp(Sender: TObject; Error: Word); var iMsgCode, iMsgTableID: Integer; begin iMsgCode := 0; with Sender as TTcpSrvClient do begin { Since we are using line mode, we will receive complete lines (as opposed to possibly just a part of a message, or any combination of pieces of messages) } RcvdLine := ReceiveStr; { Remove trailing CR/LF } while (Length(RcvdLine) > 0) and (RcvdLine[Length(RcvdLine)] in [#13, #10]) do begin RcvdLine := Copy(RcvdLine, 1, Length(RcvdLine) - 1); if Length(Trim(RcvdLine)) > 0 then begin iMsgCode := ExtractMsgCode(RcvdLine); if iMsgCode = 0 then Exit; { Get the ID value from the table for the record just entered, so the Process() method will know which record to update as either Processed or Unprocessable } end; end; ProcessMsgReceivedFromClientApp(iMsgCode, RcvdLine); end; end;
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