DELPHI中如何向某个IP不间断的发送数据


本文整理自网络,侵删。

 unit Unit1; 

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, IdUDPClient, IdBaseComponent, IdComponent,
IdUDPBase, IdUDPServer, IdSocketHandle;

type
TForm1 = class(TForm)
Button1: TButton;
IdUDPServer1: TIdUDPServer;
IdUDPClient1: TIdUDPClient;
Memo1: TMemo;
procedure IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var
str: pchar;
pos: Integer;
begin
pos := AData.Size;
str := AllocMem(pos);
AData.ReadBuffer(str^, pos);
self.Memo1.Lines.Add(Str);
FreeMem(str);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
self.IdUDPClient1.Active := false;
self.IdUDPClient1.Active := True;
self.IdUDPClient1.Send('hello my friend');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
self.IdUDPServer1.DefaultPort := 5000;//接受数据端口  www.delphitop.com 搜集整理
self.IdUDPClient1.Port := 5000;
self.IdUDPClient1.Host := '127.0.0.1';//目标机器IP
self.IdUDPServer1.Active := True;
self.IdUDPClient1.Active := True;
end;

end.

相关阅读 >>

Delphi 10.3 开发app 在android手机上获取imei

Delphi windows 编程[6] - 学习窗体生成的过程六: 最终的代码!

如何减小Delphi应用程序(exe)的大小

Delphi 16进制字符串转原字符串

Delphi内存映射 与 映射数据获取

Delphi通过post传递参数给php

Delphi jpg和bitmap互转转换的方法

Delphi使用tnethttpclient:重定向后如何给出最终的url?

Delphi form工程创建

Delphi 颜色表

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...