delphi 2010同一个窗体放入idtcpclient与idTcpServer 简单的代码却无法发送与接收(100)

  • 主题发起人 主题发起人 longcar
  • 开始时间 开始时间
L

longcar

Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下 indy 10.5.5调试发现:感觉client与server同时在read 所以就死了,但我的代码却是读发成对出现的!按理是不存在这个问题,请专家帮忙处理下unit Unit2;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, IdContext, StdCtrls, IdBaseComponent, IdComponent, IdCustomTCPServer, IdTCPServer, IdScheduler, IdSchedulerOfThread, IdSchedulerOfThreadPool, IdServerIOHandler, IdServerIOHandlerSocket, IdServerIOHandlerStack, IdTCPConnection, IdTCPClient;type TForm2 = class(TForm) IdTCPServer1: TIdTCPServer; Memo1: TMemo; Acitve: TButton; Button2: TButton; IdTCPClient1: TIdTCPClient; Edit1: TEdit; procedure IdTCPServer1Execute(AContext: TIdContext); procedure AcitveClick(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form2: TForm2;implementation{$R *.dfm}procedure TForm2.AcitveClick(Sender: TObject);begin IdTCPServer1.Active:=true;end;procedure TForm2.Button2Click(Sender: TObject);var str:string;begin IdTCPClient1.Connect; IdTCPClient1.IOHandler.WriteLn(edit1.text);// IdTCPClient1.GetResponse(200);// Memo1.Lines.Add('client :'+ IdTCPClient1.LastCmdResult.ToString); str:=IdTCPClient1.IOHandler.ReadLn(); Memo1.Lines.Add('client :'+Str ); IdTCPClient1.IOHandler.WriteLn(edit1.text); str:=IdTCPClient1.IOHandler.ReadLn(); Memo1.Lines.Add('client :'+ str);end;procedure TForm2.IdTCPServer1Execute(AContext: TIdContext);var Str:String;begin str:=AContext.Connection.IOHandler.ReadLn(); Memo1.Lines.Add('Server:'+ Str ); AContext.Connection.IOHandler.WriteLn('Well come'); str:= AContext.Connection.IOHandler.ReadLn(); Memo1.Lines.Add('Server:'+ Str); AContext.Connection.IOHandler.WriteLn('OK');end;end.
 
后退
顶部