|
INDY10中idtcpserver如何主动向idtcpclient发送一条数据
另外如果idtcpserver有多个客户端的话,怎么设置这条数据是发给哪个客户端啊? |
|
|||
|
谢谢,但是客户端怎么读取呢?我用了网上找的这个代码读不到啊
另外如果有多个客户端怎么办啊?能知道是发给哪个客户端吗? TtextTcpClient=class(TThread) private temp_string:string; procedure IOinput; public procedure execute;override; end; var Form1: TForm1; textClient:TtextTcpClient; implementation {$R *.dfm} procedure TtextTcpClient.IOinput; var temp:string; begin temp:=temp_string; end; procedure TtextTcpClient.execute; var temp:string; begin while (not textClient.Terminated) and (Form1.IdTCPClient1.Connected) do begin temp:=#13+#10; Form1.IdTCPClient1.Socket.ReadLn(temp); showmessage(temp); Synchronize(IOinput); end; end; procedure TForm1.FormCreate(Sender: TObject); begin try IdTCPClient1.Host:= '127.0.0.1'; IdTCPClient1.Port:=8899; if not IdTCPClient1.Connected then begin textClient:=TtextTcpClient.Create(true); textClient.FreeOnTerminate:=True; textClient.Resume; IdTCPClient1.Connect; end; except end; end; |
|
知道怎么判断客户端了,但是还是不会接收服务端主动发出去的这条消息
|
|
客户端使用的是ReadLn,那服务端也用WriteLN
|
|
|
还是不行啊,全部代码就是下面这些
发送改成这样:ConnContext.Connection.IOHandler.WriteLn('start'); unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,idcontext, StdCtrls; type TForm1 = class(TForm) IdTCPClient1: TIdTCPClient; IdAntiFreeze1: TIdAntiFreeze; Memo1: TMemo; procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public { Public declarations } end; TtextTcpClient=class(TThread) private temp_string:string; procedure IOinput; public procedure execute;override; end; var Form1: TForm1; textClient:TtextTcpClient; implementation {$R *.dfm} procedure TtextTcpClient.IOinput; var temp:string; begin temp:=temp_string; end; procedure TtextTcpClient.execute; var temp:string; begin while (not textClient.Terminated) and (Form1.IdTCPClient1.Connected) do begin temp:=#13+#10; temp:=Form1.IdTCPClient1.Socket.ReadLn('', 10); form1.Memo1.Lines.Add(temp); Synchronize(IOinput); end; end; procedure TForm1.FormCreate(Sender: TObject); begin try IdTCPClient1.Host:= '127.0.0.1'; IdTCPClient1.Port:=8899; if not IdTCPClient1.Connected then begin textClient:=TtextTcpClient.Create(true); textClient.FreeOnTerminate:=True; textClient.Resume; IdTCPClient1.Connect; end; except end; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin IdTCPClient1.Disconnect; end; end. |
|
procedure TtextTcpClient.execute;
var temp:string; begin form1.Memo1.Lines.Add(''); //为什么加上这句就可以了?? while (not textClient.Terminated) and (Form1.IdTCPClient1.Connected) do begin temp:=form1.IdTCPClient1.IOHandler.ReadLn; form1.Memo1.Lines.Add(temp); //Synchronize(IOinput); //而且这个也没什么用啊 end; end; |
delphi lazarus opengl
网页操作自动化, 图像分析破解,游戏开发

