Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Feb : Re: Reply Code is not valid

www.cryer.info
Managed Newsgroup Archive

Re: Reply Code is not valid

Subject:Re: Reply Code is not valid
Posted by:"Kendrick" (kkendri..@harbornet.com)
Date:Thu, 14 Feb 2008 10:17:39

> Where is SendClientMessage() being called from, though?  >

The project is based on the Indy example at CodeGear. The TIdCmdTCPServer
is in a seperate unit. The command handlers post a Windows Message which is
received by the main unit. The procedures in the main unit call the
SendClientMessage function. At the Client end, when the message is sent
calls Readln for the response. If it is expecting further information it
goes through:

       Receiving := -1; {This sets the flag}
       repeat
         if Receiving = -1 then
         begin
           s:= tcp1.IOHandler.ReadlnWait(500); {this should watch the port
for half second}
           p:= Pos('SIZE=',s);{identifies a trigger and acts on it}
           if p > 0 then begin
              ... {if all goes well then Receiving is set back to 0 to exit
loop}
           end;
         end else if Receiving > 0 then   {receiving in progress}
         inc(Receiving); {reset handled in execute}
       until Receiving in [0, 120..180]; {up to one minute delay}

I don't know if this helps but here are some snippets from the server side -
Thanks

Server Unit:
const
  WM_RUN          = WM_USER + $7587;
type
  TMyServer = class(TIdCmdTCPServer)
  private
    FMainWnd: HWND;
    procedure SetMainWnd(const Value: HWND);
    procedure CommandRUN(ASender: TIdCommand);
...

procedure TMyServer.CommandRUN(ASender: TIdCommand);
var str:PChar;
begin
  try
    str:= StrNew(PChar(ASender.Params[0])); {pointer to heap with the sql}
    PostMessage(FMainWnd, WM_RUN,
          ASender.Context.Connection.Socket.Binding.Handle,
          Integer(str));
  except
    on E: Exception do
      PostDBugMsg('TMyServer.CommandRUN '
                  + E.ClassType.ClassName + ':' + E.Message,
                  ASender.Context.Connection.Socket.Binding.Handle);
  end;
end;

In Main unit:

type
  TfmMain = class(TForm)
...
  Private
    procedure WMRun(var AMsg: TMessage); message WM_RUN;
...

procedure TfmMain.WMRun(var AMsg: TMessage);
begin
  if Dbug then mLog.Lines.Insert(0,TimeToStr(Now) + ': Prep');
  cds1.DisableControls;
  try
    try
      SqlTxt:= (PChar(aMsg.LParam));
      SendClientMessage(aMsg, 'Retreiving Data ', True, True);
      ... {does stuff and builds a stream and then sends a message to client
with a trigger}
    SendClientMessage(aMsg, 'SIZE=' + IntToStr(OutStream.Size), False,
True);
     ...

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive