求一个用INDY的UDPSERVER发送文件的源码(100分)

  • 主题发起人 主题发起人 绝对新手
  • 开始时间 开始时间

绝对新手

Unregistered / Unconfirmed
GUEST, unregistred user!
哪位高人正好做过或在做或者手头有这样的源代码能否共享一下
最好是可以多文件同时传送的
最好是有注释的

还有本人对窗口滑动理论还有所不理解 请各位达人不吝赐教
还有请教用UDP判断发送超时失败的实现方法
 
估计这位朋友很少去www.2ccc.com逛,那里不是有很多这样的代码么。
UDP是无连接的协议,没有发送超时一说,它只管发送,不管是否送到。
 
{-----------------------------------------------------------------------------
Demo Name: UDP Client
Author: <unknown - please contact me to take credit! - Allen O'Neill>
Copyright: Indy Pit Crew
Purpose:
History:
Date: 27/10/2002 01:00:36
Checked with Indy version: 9.0 - Allen O'Neill - Springboard Technologies Ltd - http://www.springboardtechnologies.com
-----------------------------------------------------------------------------
Notes:

Simple UDP client demo

}


unit UDPClientMain;

interface

uses
Windows, Messages, Graphics, Controls, Forms, Dialogs, IdWinsock2, stdctrls,
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;

implementation

const
HOSTNAMELENGTH = 80;
RECIEVETIMEOUT = 5000; // milliseconds

{$R *.DFM}

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.


----------------------------------------------------

{-----------------------------------------------------------------------------
Demo Name: UDP Server
Author: <unknown - please contact me to take credit! - Allen O'Neill>
Copyright: Indy Pit Crew
Purpose:
History:
Date: 27/10/2002 01:00:36
Checked with Indy version: 9.0 - Allen O'Neill - Springboard Technologies Ltd - http://www.springboardtechnologies.com
-----------------------------------------------------------------------------
Notes:

Simple UDP server demo

}

unit UDPServerMain;

interface

uses
Windows, Messages, Graphics, Controls, Forms, Dialogs, IdWinsock2, stdctrls,
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;

implementation

const
HOSTNAMELENGTH = 80;

{$R *.DFM}

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 &quot;' + DataStringStream.DataString + '&quot; from ' + ABinding.PeerIP + ' on port ' + IntToStr(ABinding.PeerPort));
s := 'Replied from ' + UDPServer.LocalName + ' to &quot;' + DataStringStream.DataString + '&quot;';
ABinding.SendTo(ABinding.PeerIP, ABinding.PeerPort, s[1], Length(s));
finally
DataStringStream.Free;
end;
end;


end.
 
To weiliu

不好意思 我要的不是传送字符串
还是谢谢你顶贴
 
是传流吗?
 
不是有很多么,例如这里。
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3476934
 
==>>>还有本人对窗口滑动理论还有所不理解 请各位达人不吝赐教
===>>还有请教用UDP判断发送超时失败的实现方法
===>>最好是可以多文件同时传送的


这样的代码难找。像大的通信公司视技术如命,很少有人公布些片言只语,自己摸索吧。公布出来的也只是残缺不全,没有用的。

窗口滑动窗口 在 bbs上的讨论的,你搜索看看.

UDP判断发送超时失败的实现方法, 是命令同步发送等待回复超时的意思吧,
这个在Indy里面有呀?你可以看看。
 
對數據流進行操作就行了
 
1 : 滑动窗口是网络通讯里面的很多基础书都有
大概的解释是N个窗口(N《8)同时传递 根据返回的信息 错了的从它开始望后重传。
2 :UDP无超时哦
3:用多线程 吧   
 

Similar threads

后退
顶部