小编reb*_*ble的帖子

什么应该是一个简单的TCP客户端服务器,STUCK

我被卡住了.我以前使用过服务器和客户端套接字(非indy),它们很好地异步并且易于使用.我正在尝试制作一个简单的客户端服务器.连接到客户端后,服务器会在计时器事件上发送小块数据.时间是77ms,数据块大约是100字节.我已经尽力从这里和那里以及人们的例子中找出indy.(显然,如果人们能够迅速开展工作,网上就不会有太多关于它的内容).下面我从客户端和服务器中提取了相关部分.

我将ip设置为localhost,我试图首先调试服务器端.我启动客户端,我在调试器中启动服务器.客户端连接,我可以在onconnect事件上设置一个断点,程序就在那里.现在应该发生的是计时器已启用,然后每次跳闸我发送我的数据块.(这至少在调试器中不会发生)

编译器强迫我为服务器添加onexecute事件,我现在不知道该怎么做.我尝试了一个空白事件,我尝试了一个虚拟读取.在客户端.一旦有连接它就应该从别处复制一个读线程,并在数据块发生时读取它们.现在我没有进行任何错误检查或自动检测连接丢失和尝试重新连接.

我当然感谢任何帮助,无论是在工作中还是在如何处理角落案件的提示上.

谢谢罗伯特

服务器端这应该每77毫秒发送一个数据块.................................... ................................................

type
  TForm8 = class(TForm)
    SendButton: TButton;
    SendWaveFormTimer: TTimer;
    IdUDPClient1: TIdUDPClient;
    IdTCPServer1: TIdTCPServer;

    procedure SendWaveFormTimerTimer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure IdTCPServer1Connect(AContext: TIdContext);
    procedure IdTCPServer1Execute(AContext: TIdContext);

  private
    connectedto:TIdContext;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form8: TForm8;


procedure TForm8.IdTCPServer1Connect(AContext: TIdContext);
// this is not in the main ui thread and can't call showmessage
begin
  connectedto:=acontext; // save the connected TIDcontext for use elsewhere?
  self.SendWaveFormTimer.Enabled:=true; {set the send timer}
end;

procedure TForm8.SendWaveFormTimerTimer(Sender: …
Run Code Online (Sandbox Code Playgroud)

delphi client-server indy10 firemonkey

1
推荐指数
1
解决办法
625
查看次数

标签 统计

client-server ×1

delphi ×1

firemonkey ×1

indy10 ×1