idtcpserver接收stream

type

 

 TServerHandleThread = class(TThread)

 private

   Mstr:string;

   procedure HandleInput;

 protected

   procedure Execute; override;

 public

   constructor Create(AStyle:Boolean;Str:String);overload;

   destructor Destroy; override;

 end;

 

implementation

 

{ TServerHandleThread }

 

constructorTServerHandleThread.Create(AStyle: Boolean;

 Str: String);

begin

 inherited Create(AStyle);

 Mstr:=Str;

 FreeOnTerminate:=true;

end;

 

destructor TServerHandleThread.Destroy;

begin

 inherited;

end;

 

procedure TServerHandleThread.Execute;

begin

 inherited;

 FreeOnTerminate:=True;

  try

   Synchronize(HandleInput);

 finally

   Free;

 end;

end;

 

procedure TServerHandleThread.HandleInput;

var

 command,content:String;

begin

  try

   command:=Copy(Mstr,0,5);

   content:=AnsiReplaceStr(Mstr,command,'');

   if command='_SOR_' then

   begin

     OptionPage.fornewscores(content);

   end

   else if command='_INF_' then

   begin

     OptionPage.forconnectchange(StrToIntDef(content,0),True);

   end

   else if command='_DIS_' then

   begin

     OptionPage.forconnectchange(StrToIntDef(content,0),False);

   end;

 except

 end;

end;

 

end.

 

 

 

Tcpserver.OnExecute

var

 temp:TStringStream;

 Dstr:string;

 mythread:TServerHandleThread;

begin

 temp:=TStringStream.Create('');

  try

   with AThread.Connection do

   begin

     ReadStream(temp);

     temp.Position:=0;

     Dstr:=temp.DataString;

   end;

 finally

   temp.Free;

 end;

 

 mythread:=TServerHandleThread.Create(False,Dstr);

End;

在execute中先由线程来接收,之后给新的线程来处理


现在我就想到这一个方法来处理    不知道会不会有bug

你可能感兴趣的:(idtcpserver接收stream)