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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值