delphi网络疑难(500分相送)

alongjuan 2002-06-05 11:06:34
我做的东西是一个局域网中:
第一个程序要实现的功能是:先去查找局域网里面一个具体的IP号电脑,如果找到
就得到那个电脑的共享文件夹,点击就将这个文件夹保存起来,如果觉得这个文件很重要,你可以拷贝到自己的电脑里面。

第二个程序要实现的功能是:要给局域网里的某一台电脑发送一个消息,问是否接受我
发送的一个文件给他,就像QICQ里面的那个传送文件的功能,就此一个功能而已。

谁有代码或者提供参考者,给我发信
E-mail: alongjuan@etang.com

我在线等待,完毕给分。

...全文
20 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
gdutqhl 2002-06-05
  • 打赏
  • 举报
回复
第二题你可以参考tcp/ip之delphi程序指南,里面有很详细的介绍及源代码。
alongjuan 2002-06-05
  • 打赏
  • 举报
回复
第一题 给分


第二题有难度,所以高手们不惜指点!
alongjuan 2002-06-05
  • 打赏
  • 举报
回复
第二个拷贝的问题是:

要将其拷贝到指定的文件夹里面
naughtyboy 2002-06-05
  • 打赏
  • 举报
回复
2,网上邻居上实现文件的拷贝
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
StaticText1: TStaticText;
StaticText2: TStaticText;
OpenDialog1: TOpenDialog;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
if opendialog1.Execute then
edit1.text:=opendialog1.FileName ;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
CopyFile(pchar(edit1.text),pchar(edit2.text),False);
end;

end.
naughtyboy 2002-06-05
  • 打赏
  • 举报
回复
我这里有两段程序
你把它综合一下

1,获得指定计算机的共享信息
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TNetResourceArray = ^TNetResource; //网络资源类型的数组
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Memo1: TMemo;
StaticText1: TStaticText;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

Function GetUserResource( UserName : string ; var List : TStringList ) : Boolean;
Var
NetResource : TNetResource;
Buf : Pointer;
Count,BufSize,Res : DWord;
Ind : Integer;
lphEnum : THandle;
Temp : TNetResourceArray;
Begin
Result := False;
List.Clear;
FillChar(NetResource, SizeOf(NetResource), 0); //初始化网络层次信息
NetResource.lpRemoteName := @UserName[1]; //指定计算机名称
Res := WNetOpenEnum( RESOURCE_GLOBALNET, RESOURCETYPE_ANY,RESOURCEUSAGE_CONNECTABLE, @NetResource,lphEnum);
//获取指定计算机的网络资源句柄
If Res <> NO_ERROR Then exit; //执行失败
While True Do //列举指定工作组的网络资源
Begin
Count := $FFFFFFFF; //不限资源数目
BufSize := 8192; //缓冲区大小设置为8K
GetMem(Buf, BufSize); //申请内存,用于获取工作组信息
Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);
//获取指定计算机的网络资源名称
If Res = ERROR_NO_MORE_ITEMS Then break;//资源列举完毕
If (Res <> NO_ERROR) then Exit; //执行失败
Temp := TNetResourceArray(Buf);
For Ind := 0 to Count - 1 do
Begin
List.Add(Temp^.lpRemoteName);
Inc(Temp);
End;
End;
Res := WNetCloseEnum(lphEnum); //关闭一次列举
If Res <> NO_ERROR Then exit; //执行失败
Result := True;
FreeMem(Buf);
End;


procedure TForm1.Button1Click(Sender: TObject);
var
List:TstringList;
i:integer;
begin
try
List:=TstringList.Create;
if GetUserResource(edit1.text,List) then
if List.count=0 then //指定计算机下没有找到共享资源
begin
memo1.Lines.Add (edit1.text+'下没有找到共享资源!');
end
else
memo1.Lines.Add (edit1.text+'下的所有共享资源如下:');
for i:=0 to List.Count-1 do
begin
Memo1.lines.Add (List.strings[i]);
end;
finally
List:=TstringList.Create; //如有异常则释放分配的资源
end;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.Lines .clear;
end;

end.
newnewworm 2002-06-05
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

const
RAS_MaxDeviceType = 16;//设备类型名称长度
RAS_MaxEntryName = 256;//连接名称最大长度
RAS_MaxDeviceName = 128;//设备名称最大长度
RAS_MaxIpAddress = 15;//IP地址的最大长度
RASP_PppIp = $8021;//拨号连接的协议类型,该数值表示PPP连接

type
HRASCONN = DWORD;//拨号连接句柄的类型
RASCONN = record//活动的拨号连接的句柄和设置信息
dwSize : DWORD;//该结构所占内存的大小(Bytes), 一般设置为SizeOf(RASCONN)
hrasconn : HRASCONN;//活动连接的句柄
szEntryName : array[0..RAS_MaxEntryName] of char;
//活动连接的名称
szDeviceType : array[0..RAS_MaxDeviceType] of char;
//活动连接的所用的设备类型
szDeviceName : array[0..RAS_MaxDeviceName] of char;
//活动连接的所用的设备名称
end;
TRASPPPIP = record//活动的拨号连接的动态IP地址信息
dwSize : DWORD;//该结构所占内存的大小(Bytes),一般设置为SizeOf(TRASPPPIP)
dwError : DWORD;//错误类型标识符
szIpAddress : array[0..RAS_MaxIpAddress] of char;
//活动的拨号连接的IP地址
end;
type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function RasEnumConnections(var lprasconn : RASCONN;
//接收活动连接的缓冲区的指针
var lpcb: DWORD;//缓冲区大小
var lpcConnections : DWORD//实际的活动连接数
) : DWORD; stdcall;
function RasEnumConnections;external 'Rasapi32.dll'
name 'RasEnumConnectionsA';
//获取指定活动的拨号连接的动态IP信息
function RasGetProjectionInfo(
hrasconn : HRasConn;//指定活动连接的句柄
rasprojection : DWORD;//RAS连接类型
var lpprojection : TRASPPPIP;//接收动态IP信息的缓冲区
var lpcb : DWord//接收缓冲区的大小
) : DWORD;stdcall;
function RasGetProjectionInfo;external
'Rasapi32.dll' name 'RasGetProjectionInfoA';
var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
const
MaxConnections = 10;//假设最多有10个活动的拨号连接
var
connections : array[0..MaxConnections-1] of RASCONN;
//拨号连接数组
longSize : dword;
intAvailabelConnections : dword;
//活动的拨号连接的实际数目
intIndex : integer;
strTemp : string;
dwResult : DWORD;
dwSize : DWORD;
RASpppIP : TRASPPPIP;
//活动的拨号连接的动态IP地址信息
begin
connections[0].dwSize:=sizeof(RASCONN);
longSize:=MaxConnections * connections[0].dwSize;
//接收活动连接的缓冲区大小
intAvailabelConnections:=0;
//获取所有活动的拨号连接的信息(连接句柄和设置信息)
dwResult:=RasEnumConnections(connections[0],longSize,intAvailabelConnections);
if 0<>dwResult then memo1.lines.add('错误:'+inttostr(dwResult))
else
begin
memo1.lines.add('现有的活动连接有'+IntToStr(intAvailabelConnections)+'个');
//显示所有活动的拨号连接的信息(设置信息和动态IP地址)
for intIndex:=0 to intAvailabelConnections-1 do
begin
//显示一个活动的拨号连接的设置信息
strTemp := '连接名称:'+StrPAS(connections[intIndex].szEntryName)
+ ',设备类型:'+StrPAS(connections[intIndex].szDeviceType)
+ ',设备名称:'+StrPAS(connections[intIndex].szDeviceName);
memo1.lines.add( strTemp );
//显示一个活动的拨号连接的动态IP地址
dwSize := SizeOf(RASpppIP);
RASpppIP.dwSize := dwSize;
dwResult := RASGetProjectionInfo(connections[intIndex].hRasConn,RASP_PppIp,RasPPPIP,dwSize);//获取动态IP地址
if 0 <> dwResult then memo1.lines.add('错误:'+inttostr( dwResult ))
else memo1.lines.add('动态地址:'+StrPas(RASpppIP.szIPAddress));
end;
end;
end;

end.
debussy 2002-06-05
  • 打赏
  • 举报
回复
没有看我给你的代码吗?我测试通过了的。
http://www.csdn.net/expert/topic/779/779595.xml?temp=1.983279E-02


PS:真有500分那么多吗(流口水中...)

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧