我使用了indy中idtcpdemo中的例子,然后对client中的
procedure TClientFrmMain.ButtonSendClick(Sender: TObject);
var
CommBlock : TCommBlock;
i:integer;
begin for I:=0 to 200 do //我修改的内容
begin commblock.Command:= EditCommand.Text; // assign the data
CommBlock.MyUserName := Client.LocalName;
CommBlock.Msg := EditMessage.Text;
CommBlock.ReceiverName := EditRecipient.Text; Client.WriteBuffer (CommBlock, SizeOf (CommBlock), true);
end;
end;
进行修改,然后运行,但是client,没有接收到server发送回来的信息。
请问这时为什么?该如何解决?谢谢进行修改
procedure TClientFrmMain.ButtonSendClick(Sender: TObject);
var
CommBlock : TCommBlock;
i:integer;
begin for I:=0 to 200 do //我修改的内容
begin commblock.Command:= EditCommand.Text; // assign the data
CommBlock.MyUserName := Client.LocalName;
CommBlock.Msg := EditMessage.Text;
CommBlock.ReceiverName := EditRecipient.Text; Client.WriteBuffer (CommBlock, SizeOf (CommBlock), true);
end;
end;
进行修改,然后运行,但是client,没有接收到server发送回来的信息。
请问这时为什么?该如何解决?谢谢进行修改
你发了,必须要收一下,才能
unit ClientFrmMainUnit;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, StdCtrls,
GlobalUnit, DB, ADODB;type
TClientFrmMain = class(TForm)
CBClientActive: TCheckBox;
IncomingMessages: TMemo;
Label1: TLabel;
Client: TIdTCPClient;
Label2: TLabel;
EditCommand: TComboBox;
Label3: TLabel;
EditMessage: TEdit;
Label4: TLabel;
EditRecipient: TEdit;
ButtonSend: TButton;
ADOConnection1: TADOConnection;
adoq1: TADOQuery; procedure CBClientActiveClick(Sender: TObject);
procedure ButtonSendClick(Sender: TObject); private public end; TClientHandleThread = class(TThread)
private
CB: TCommBlock; procedure HandleInput; protected
procedure Execute; override; end;var
ClientFrmMain: TClientFrmMain;
ClientHandleThread: TClientHandleThread; // variable (type see above)implementation{$R *.DFM}procedure TClientHandleThread.HandleInput;
begin
if CB.Command = 'MESSAGE' then
ClientFrmMain.IncomingMessages.Lines.Add (CB.MyUserName + ': ' + CB.Msg)
else
if CB.Command = 'DIALOG' then
MessageDlg ('"'+CB.MyUserName+'" sends you this message:'+#13+CB.Msg, mtInformation, [mbOk], 0)
else // unknown command
MessageDlg('Unknown command "'+CB.Command+'" containing this message:'+#13+CB.Msg, mtError, [mbOk], 0);
end;procedure TClientHandleThread.Execute;
begin
while not Terminated do
begin
if not ClientFrmMain.Client.Connected then
Terminate
else
try
ClientFrmMain.Client.ReadBuffer(CB, SizeOf (CB));
Synchronize(HandleInput);
except
end;
end;
end;procedure TClientFrmMain.CBClientActiveClick(Sender: TObject);
begin
if CBClientActive.Checked then
begin
try
Client.Connect(10000); // in Indy < 8.1 leave the parameter away ClientHandleThread := TClientHandleThread.Create(True);
ClientHandleThread.FreeOnTerminate:=True;
ClientHandleThread.Resume;
except
on E: Exception do MessageDlg ('Error while connecting:'+#13+E.Message, mtError, [mbOk], 0);
end;
end
else
begin
ClientHandleThread.Terminate;
Client.Disconnect;
end; ButtonSend.Enabled := Client.Connected;
CBClientActive.Checked := Client.Connected;
end;procedure TClientFrmMain.ButtonSendClick(Sender: TObject);
var
CommBlock : TCommBlock;
i:integer;
begin
{with ADOQ1 do
begin
close;
sql.clear;
sql.add('select top 20 * from clientdat where state=''false'' order by msg');
open;
for i:=0 to recordcount-1 do
begin
label1.Caption:= fieldbyname('commandtype').asstring;
commblock.id:='';
commblock.Command:='MESSAGE';
commblock.MyUserName:='11.37.35.78';
commblock.Msg:=fieldbyname('msg').asstring;
commblock.ReceiverName:='';
commblock.msgtype:='install pro';
Client.WriteBuffer (CommBlock, SizeOf (CommBlock), true);
// sendmsg(fieldbyname('commandtype').asstring,fieldbyname('ipaddress').asstring,fieldbyname('messagetype').asstring,fieldbyname('msg').asstring,fieldbyname('sendtime').asstring,'123456',0);
next;
end;} for I:=0 to 200 do //我增加的代码
begin commblock.Command:= EditCommand.Text; // assign the data
CommBlock.MyUserName := Client.LocalName;
CommBlock.Msg := EditMessage.Text;
CommBlock.ReceiverName := EditRecipient.Text; Client.WriteBuffer (CommBlock, SizeOf (CommBlock), true);
end;
end;
//end;
end.