绝
绝对新手
Unregistered / Unconfirmed
GUEST, unregistred user!
我把一个窗体(窗体中有一个IdUDPServer控件)做成DLL 然后把这个DLL用加载到我的进程中DLL会建立一个新线程然后在新线程中创建窗体 源代码如下
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent, IdComponent,
IdUDPBase, IdUDPServer, IdSocketHandle;
type
TForm2 = class(TForm)
u1: TIdUDPServer;
IdAntiFreeze1: TIdAntiFreeze;
procedure FormCreate(Sender: TObject);
procedure u1UDPRead(Sender: TObject;
AData: TStream;
ABinding: TIdSocketHandle);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TMain = class(TThread)
private
{ Private declarations }
protected
procedure Execute;
override;
end;
var
Form2: TForm2;
Main: TMain;
implementation
{$R *.dfm}
procedure TMain.Execute;
var
Msg: TMsg;
begin
Form2:=TForm2.Create(Form2);
Form2.Show;
while GetMessage(Msg, 0, 0, 0)do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
u1.DefaultPort:= 10084;
u1.Active:= true;
end;
procedure TForm2.u1UDPRead(Sender: TObject;
AData: TStream;
ABinding: TIdSocketHandle);
var
a: TStringList;
begin
a:= TStringlist.Create;
AData.Read(a,AData.Size);
showmessage(a[0]);
a.Free;
end;
end.
运行后防火墙显示端口确实已经打开 但是由另一端发送的信息后并没有弹出对话框。就像没收到消息一样。
这是另一端的源代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent,
IdComponent, IdUDPBase, IdUDPServer;
type
TForm1 = class(TForm)
u2: TIdUDPServer;
IdAntiFreeze1: TIdAntiFreeze;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
a:TStringList;
begin
a:= TStringlist.Create;
a.Add('11111');
showmessage
u2.SendBuffer('127.0.0.1',10084,a,sizeof(a));
a.free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
u2.DefaultPort:= 10085;
u2.Active := true;
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent, IdComponent,
IdUDPBase, IdUDPServer, IdSocketHandle;
type
TForm2 = class(TForm)
u1: TIdUDPServer;
IdAntiFreeze1: TIdAntiFreeze;
procedure FormCreate(Sender: TObject);
procedure u1UDPRead(Sender: TObject;
AData: TStream;
ABinding: TIdSocketHandle);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TMain = class(TThread)
private
{ Private declarations }
protected
procedure Execute;
override;
end;
var
Form2: TForm2;
Main: TMain;
implementation
{$R *.dfm}
procedure TMain.Execute;
var
Msg: TMsg;
begin
Form2:=TForm2.Create(Form2);
Form2.Show;
while GetMessage(Msg, 0, 0, 0)do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
u1.DefaultPort:= 10084;
u1.Active:= true;
end;
procedure TForm2.u1UDPRead(Sender: TObject;
AData: TStream;
ABinding: TIdSocketHandle);
var
a: TStringList;
begin
a:= TStringlist.Create;
AData.Read(a,AData.Size);
showmessage(a[0]);
a.Free;
end;
end.
运行后防火墙显示端口确实已经打开 但是由另一端发送的信息后并没有弹出对话框。就像没收到消息一样。
这是另一端的源代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent,
IdComponent, IdUDPBase, IdUDPServer;
type
TForm1 = class(TForm)
u2: TIdUDPServer;
IdAntiFreeze1: TIdAntiFreeze;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
a:TStringList;
begin
a:= TStringlist.Create;
a.Add('11111');
showmessage
u2.SendBuffer('127.0.0.1',10084,a,sizeof(a));
a.free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
u2.DefaultPort:= 10085;
u2.Active := true;
end;
end.