首先新建服务端。
如下图所示建立工程:
代码如下:
1.unit ServerUnit;2.3.interface4.5.uses6. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,7. Dialogs, IdBaseComponent, IdComponent, IdUDPBase, IdUDPServer, StdCtrls,8. IdSocketHandle, IdGlobal;9.10.type11. TServerForm = class(TForm)12. Label1: TLabel;13. Edit1: TEdit;14. Label2: TLabel;15. Edit2: TEdit;16. Label3: TLabel;17. Edit3: TEdit;18. IdUDPServer1: TIdUDPServer;19. procedure IdUDPServer1UDPRead(AThread: TIdUDPListenerThread; AData: TBytes;20. ABinding: TIdSocketHandle);21. procedure FormCreate(Sender: TObject);22. private23. { Private declarations }24. public25. { Public declarations }26. end;27.28.var29. ServerForm: TServerForm;30.31.implementation32.33.{$R *.dfm}34.35.procedure TServerForm.FormCreate(Sender: TObject);36.begin37. IdUDPServer1.DefaultPort := 3030;38. IdUDPServer1.Active := True;39.40. Edit1.ReadOnly := True;41. Edit2.ReadOnly := True;42. Edit3.ReadOnly := True;43.end;44.45.procedure TServerForm.IdUDPServer1UDPRead(AThread: TIdUDPListenerThread;46. AData: TBytes; ABinding: TIdSocketHandle);47.begin48. Edit1.Text := ABinding.PeerIP;49. Edit2.Text := IntToStr(ABinding.PeerPort);50. Edit3.Text := BytesToString(AData);51.52. IdUDPServer1.Send(ABinding.PeerIP, ABinding.PeerPort, TimeToStr(Time) + ' => Server received the message!');53.end;54.55.end.
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索edit
, edit control
, true
, readonly
procedure
indy udp、indy10 udp 中文、delphi indy、delphi indy10 demo、delphi7 indy10 下载,以便于您获取更多的相关知识。
时间: 2024-11-18 14:49:28