我使用Delphi6的Demo,修改了IdUDPClient中的IP地址后他发给我的我能收到,我发给他的却不能收到,不知道为什么啊
IP从QQ上获取:我的218.85.251.75:4001
他的:61.183.235.161:10928
是不是因为他的端口太奇怪了?******Client******* object UDPAntiFreeze: TIdAntiFreeze
OnlyWhenIdle = False
Left = 268
Top = 16
end
object UDPClient: TIdUDPClient
Host = '218.6.48.133'
Port = 8090
ReceiveTimeout = 0
Left = 240
Top = 16
end
{***************************************************************
*
* Project : UDPClient
* Unit Name: UDPClientMain
* Purpose : UDP demo - client project
* Version : 1.0
* Date : Wed 25 Apr 2001 - 01:44:24
* Author : <unknown>
* History :
* Tested : Wed 25 Apr 2001 // Allen O'Neill <[email protected]>
*
****************************************************************}unit UDPClientMain;interfaceuses
{$IFDEF Linux}
QGraphics, QControls, QForms, QDialogs, QStdCtrls,
{$ELSE}
windows, messages, graphics, controls, forms, dialogs, Winsock, stdctrls,
{$ENDIF}
SysUtils, Classes, IdBaseComponent, IdAntiFreezeBase, IdAntiFreeze,
IdComponent, IdUDPBase, IdUDPClient, IdStack;type
TUDPMainForm = class(TForm)
SourceGroupBox: TGroupBox;
HostNameLabel: TLabel;
HostAddressLabel: TLabel;
HostName: TLabel;
HostAddress: TLabel;
UDPAntiFreeze: TIdAntiFreeze;
PortLabel: TLabel;
Port: TLabel;
DestinationLabel: TLabel;
DestinationAddress: TLabel;
BufferSizeLabel: TLabel;
BufferSize: TLabel;
UDPMemo: TMemo;
SendButton: TButton;
UDPClient: TIdUDPClient;
procedure FormCreate(Sender: TObject);
procedure SendButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
UDPMainForm: TUDPMainForm;implementationconst
HOSTNAMELENGTH = 80;
RECIEVETIMEOUT = 5000; // milliseconds{$IFDEF MSWINDOWS}{$R *.dfm}{$ELSE}{$R *.xfm}{$ENDIF}procedure TUDPMainForm.FormCreate(Sender: TObject);
begin
Randomize; // remove if you want reproducible results.
HostName.Caption := UDPClient.LocalName;
HostAddress.Caption := GStack.LocalAddress;
Port.Caption := IntToStr(UDPClient.Port);
DestinationAddress.Caption := UDPClient.Host;
BufferSize.Caption := IntToStr(UDPClient.BufferSize);
UDPClient.ReceiveTimeout := RECIEVETIMEOUT;
end;procedure TUDPMainForm.SendButtonClick(Sender: TObject);
var
MessageID: Integer;
ThisMessage: String;
ReceivedString: String;
begin
MessageID := Random(MAXINT);
ThisMessage := 'Message: ' + IntToStr(MessageID);
UDPMemo.Lines.Add('Sending ' + ThisMessage);
UDPClient.Send(ThisMessage);
ReceivedString := UDPClient.ReceiveString();
if ReceivedString = '' then
UDPMemo.Lines.Add('No response received from the server after ' + IntToStr(UDPClient.ReceiveTimeout) + ' millseconds.')
else
UDPMemo.Lines.Add('Received: ' + ReceivedString)
end;end. object UDPServer: TIdUDPServer
Bindings = <>
DefaultPort = 8090
OnUDPRead = UDPServerUDPRead
Left = 240
Top = 16
end
object UDPAntiFreeze: TIdAntiFreeze
OnlyWhenIdle = False
Left = 268
Top = 16
end
******Server*******
{***************************************************************
*
* Project : UDPServer
* Unit Name: UDPServerMain
* Purpose : UDP demo - server project
* Version : 1.0
* Date : Wed 25 Apr 2001 - 01:43:04
* Author : <unknown>
* History :
* Tested : Wed 25 Apr 2001 // Allen O'Neill <[email protected]>
*
****************************************************************}unit UDPServerMain;interfaceuses
{$IFDEF Linux}
QGraphics, QControls, QForms, QDialogs, QStdCtrls,
{$ELSE}
windows, messages, graphics, controls, forms, dialogs, IdWinsock, stdctrls,
{$ENDIF}
SysUtils, Classes, IdBaseComponent, IdAntiFreezeBase, IdAntiFreeze,
IdComponent, IdUDPBase, IdUDPClient, IdStack, IdUDPServer, IdSocketHandle;
type
TUDPMainForm = class(TForm)
SourceGroupBox: TGroupBox;
HostNameLabel: TLabel;
HostAddressLabel: TLabel;
HostName: TLabel;
HostAddress: TLabel;
UDPServer: TIdUDPServer;
UDPAntiFreeze: TIdAntiFreeze;
PortLabel: TLabel;
Port: TLabel;
BufferSizeLabel: TLabel;
BufferSize: TLabel;
UDPMemo: TMemo;
procedure FormCreate(Sender: TObject);
procedure UDPServerUDPRead(Sender: TObject; AData: TStream; ABinding: TIdSocketHandle);
private
{ Private declarations }
public
{ Public declarations }
end;var
UDPMainForm: TUDPMainForm;implementationconst
HOSTNAMELENGTH = 80;{$IFDEF MSWINDOWS}{$R *.dfm}{$ELSE}{$R *.xfm}{$ENDIF}procedure TUDPMainForm.FormCreate(Sender: TObject);
begin
HostName.Caption := UDPServer.LocalName;
HostAddress.Caption := GStack.LocalAddress;
Port.Caption := IntToStr(UDPServer.DefaultPort);
BufferSize.Caption := IntToStr(UDPServer.BufferSize);
UDPServer.Active := True;
end;procedure TUDPMainForm.UDPServerUDPRead(Sender: TObject; AData: TStream; ABinding: TIdSocketHandle);
var
DataStringStream: TStringStream;
s: String;
begin
DataStringStream := TStringStream.Create('');
try
DataStringStream.CopyFrom(AData, AData.Size);
UDPMemo.Lines.Add('Received "' + DataStringStream.DataString + '" from ' + ABinding.PeerIP + ' on port ' + IntToStr(ABinding.PeerPort));
s := 'Replied from ' + UDPServer.LocalName + ' to "' + DataStringStream.DataString + '"';
ABinding.SendTo(ABinding.PeerIP, ABinding.PeerPort, s[1], Length(s));
finally
DataStringStream.Free;
end;
end;
end.
IP从QQ上获取:我的218.85.251.75:4001
他的:61.183.235.161:10928
是不是因为他的端口太奇怪了?******Client******* object UDPAntiFreeze: TIdAntiFreeze
OnlyWhenIdle = False
Left = 268
Top = 16
end
object UDPClient: TIdUDPClient
Host = '218.6.48.133'
Port = 8090
ReceiveTimeout = 0
Left = 240
Top = 16
end
{***************************************************************
*
* Project : UDPClient
* Unit Name: UDPClientMain
* Purpose : UDP demo - client project
* Version : 1.0
* Date : Wed 25 Apr 2001 - 01:44:24
* Author : <unknown>
* History :
* Tested : Wed 25 Apr 2001 // Allen O'Neill <[email protected]>
*
****************************************************************}unit UDPClientMain;interfaceuses
{$IFDEF Linux}
QGraphics, QControls, QForms, QDialogs, QStdCtrls,
{$ELSE}
windows, messages, graphics, controls, forms, dialogs, Winsock, stdctrls,
{$ENDIF}
SysUtils, Classes, IdBaseComponent, IdAntiFreezeBase, IdAntiFreeze,
IdComponent, IdUDPBase, IdUDPClient, IdStack;type
TUDPMainForm = class(TForm)
SourceGroupBox: TGroupBox;
HostNameLabel: TLabel;
HostAddressLabel: TLabel;
HostName: TLabel;
HostAddress: TLabel;
UDPAntiFreeze: TIdAntiFreeze;
PortLabel: TLabel;
Port: TLabel;
DestinationLabel: TLabel;
DestinationAddress: TLabel;
BufferSizeLabel: TLabel;
BufferSize: TLabel;
UDPMemo: TMemo;
SendButton: TButton;
UDPClient: TIdUDPClient;
procedure FormCreate(Sender: TObject);
procedure SendButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
UDPMainForm: TUDPMainForm;implementationconst
HOSTNAMELENGTH = 80;
RECIEVETIMEOUT = 5000; // milliseconds{$IFDEF MSWINDOWS}{$R *.dfm}{$ELSE}{$R *.xfm}{$ENDIF}procedure TUDPMainForm.FormCreate(Sender: TObject);
begin
Randomize; // remove if you want reproducible results.
HostName.Caption := UDPClient.LocalName;
HostAddress.Caption := GStack.LocalAddress;
Port.Caption := IntToStr(UDPClient.Port);
DestinationAddress.Caption := UDPClient.Host;
BufferSize.Caption := IntToStr(UDPClient.BufferSize);
UDPClient.ReceiveTimeout := RECIEVETIMEOUT;
end;procedure TUDPMainForm.SendButtonClick(Sender: TObject);
var
MessageID: Integer;
ThisMessage: String;
ReceivedString: String;
begin
MessageID := Random(MAXINT);
ThisMessage := 'Message: ' + IntToStr(MessageID);
UDPMemo.Lines.Add('Sending ' + ThisMessage);
UDPClient.Send(ThisMessage);
ReceivedString := UDPClient.ReceiveString();
if ReceivedString = '' then
UDPMemo.Lines.Add('No response received from the server after ' + IntToStr(UDPClient.ReceiveTimeout) + ' millseconds.')
else
UDPMemo.Lines.Add('Received: ' + ReceivedString)
end;end. object UDPServer: TIdUDPServer
Bindings = <>
DefaultPort = 8090
OnUDPRead = UDPServerUDPRead
Left = 240
Top = 16
end
object UDPAntiFreeze: TIdAntiFreeze
OnlyWhenIdle = False
Left = 268
Top = 16
end
******Server*******
{***************************************************************
*
* Project : UDPServer
* Unit Name: UDPServerMain
* Purpose : UDP demo - server project
* Version : 1.0
* Date : Wed 25 Apr 2001 - 01:43:04
* Author : <unknown>
* History :
* Tested : Wed 25 Apr 2001 // Allen O'Neill <[email protected]>
*
****************************************************************}unit UDPServerMain;interfaceuses
{$IFDEF Linux}
QGraphics, QControls, QForms, QDialogs, QStdCtrls,
{$ELSE}
windows, messages, graphics, controls, forms, dialogs, IdWinsock, stdctrls,
{$ENDIF}
SysUtils, Classes, IdBaseComponent, IdAntiFreezeBase, IdAntiFreeze,
IdComponent, IdUDPBase, IdUDPClient, IdStack, IdUDPServer, IdSocketHandle;
type
TUDPMainForm = class(TForm)
SourceGroupBox: TGroupBox;
HostNameLabel: TLabel;
HostAddressLabel: TLabel;
HostName: TLabel;
HostAddress: TLabel;
UDPServer: TIdUDPServer;
UDPAntiFreeze: TIdAntiFreeze;
PortLabel: TLabel;
Port: TLabel;
BufferSizeLabel: TLabel;
BufferSize: TLabel;
UDPMemo: TMemo;
procedure FormCreate(Sender: TObject);
procedure UDPServerUDPRead(Sender: TObject; AData: TStream; ABinding: TIdSocketHandle);
private
{ Private declarations }
public
{ Public declarations }
end;var
UDPMainForm: TUDPMainForm;implementationconst
HOSTNAMELENGTH = 80;{$IFDEF MSWINDOWS}{$R *.dfm}{$ELSE}{$R *.xfm}{$ENDIF}procedure TUDPMainForm.FormCreate(Sender: TObject);
begin
HostName.Caption := UDPServer.LocalName;
HostAddress.Caption := GStack.LocalAddress;
Port.Caption := IntToStr(UDPServer.DefaultPort);
BufferSize.Caption := IntToStr(UDPServer.BufferSize);
UDPServer.Active := True;
end;procedure TUDPMainForm.UDPServerUDPRead(Sender: TObject; AData: TStream; ABinding: TIdSocketHandle);
var
DataStringStream: TStringStream;
s: String;
begin
DataStringStream := TStringStream.Create('');
try
DataStringStream.CopyFrom(AData, AData.Size);
UDPMemo.Lines.Add('Received "' + DataStringStream.DataString + '" from ' + ABinding.PeerIP + ' on port ' + IntToStr(ABinding.PeerPort));
s := 'Replied from ' + UDPServer.LocalName + ' to "' + DataStringStream.DataString + '"';
ABinding.SendTo(ABinding.PeerIP, ABinding.PeerPort, s[1], Length(s));
finally
DataStringStream.Free;
end;
end;
end.
解决方案 »
- delphi简单问题,在线等
- DBLookupComboBox1做选择框,只设置ListSource,怎样让窗体一启动,DBLookupComboBox1的内容就自动显示为ListSource的默认记录上,我现在
- 谁能介绍一下:有没有与Word兼容比较好的控件(For Delphi)?
- 在xp编译的程序为什么在98下会有乱码现象,怎么解决?
- 问个制作安装包的问题?如果的我的程序的数据库用的是access的话,程序做好了,放到没有dephi的机器上?
- 各位,请问我如何用程序来控制其它程序对我的硬件进行改动?
- DSPack使用问题
- DirectX抓屏高手请进
- 急!一个有关client/server中主从表的问题?在线等待
- 我在PUBLIC 中声明过了但在另一个单元也不能引用
- karach 过来接分
- 在image控件上如何根据鼠标位置的不同显示不同Hint信息?
不过我建议你用TIdUDPServer来做,