W
Writer
Unregistered / Unconfirmed
GUEST, unregistred user!
问题一(100分)、
我用TFileStream编文件分割器,在定义缓冲时出现错误。
请看下面的代码:
var
Buffer:array [1..1048576] of PChar;
在调试时就出现错误??而:
var
Buffer:array [1..544288] of PChar;
就可以通过。
是不是缓冲有上限的??(有相关资料者可另加50分)
问题二(200分)。
关于TServerSocket和TClientSocket之间传输文件时的怪现像。
//TClientSocket端,收文件的一端
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
CS: TClientSocket;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure CSRead(Sender: TObject
Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
CX:Integer;
FS:TFileStream;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
CS.Active:=True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
CS.Socket.SendText('DL');
CX:=1888256;
FS:=TFileStream.Create('E:/Oicq.exe',fmCreate);
end;
procedure TForm1.CSRead(Sender: TObject
Socket: TCustomWinSocket);
var
Buf:array [1..2048] of Char;
begin
if CX>2048 then
begin
Socket.ReceiveBuf(Buf,SizeOf(Buf));
FS.Write(Buf,SizeOf(Buf));
CX:=CX-SizeOf(Buf);
Socket.SendText('DL');
end
else
begin
Socket.ReceiveBuf(Buf,CX);
FS.Write(Buf,CX);
Fs.Free;
end;
end;
end.
//TServerSocket端,为发送方
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp;
type
TForm1 = class(TForm)
SS: TServerSocket;
procedure FormCreate(Sender: TObject);
procedure SSClientRead(Sender: TObject
Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
FS:TFileStream;
CX:integer;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
FS:=TfileStream.Create('E:/qq/oicq.exe',fmOpenread);
cx:=1888256;
end;
procedure TForm1.SSClientRead(Sender: TObject
Socket: TCustomWinSocket);
var
Buf:array [1..2048] of char;
begin
if socket.ReceiveText='DL' then
begin
if cx<=sizeof(buf) then
begin
fs.Read(buf,cx);
socket.SendBuf(buf,cx);
end
else
begin
fs.Read(buf,sizeof(buf));
socket.SendBuf(buf,sizeof(buf));
Cx:=cx-sizeof(buf);
end;
end;
end;
end.
现象:当第一次发送文件成功,但第二次发送完成后,发过来的文件虽然和TClientSocket端的原文件大小一样,但就不能运行,图标变为了DOS的可执行文件的图标。请指出错处。
我用TFileStream编文件分割器,在定义缓冲时出现错误。
请看下面的代码:
var
Buffer:array [1..1048576] of PChar;
在调试时就出现错误??而:
var
Buffer:array [1..544288] of PChar;
就可以通过。
是不是缓冲有上限的??(有相关资料者可另加50分)
问题二(200分)。
关于TServerSocket和TClientSocket之间传输文件时的怪现像。
//TClientSocket端,收文件的一端
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
CS: TClientSocket;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure CSRead(Sender: TObject
Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
CX:Integer;
FS:TFileStream;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
CS.Active:=True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
CS.Socket.SendText('DL');
CX:=1888256;
FS:=TFileStream.Create('E:/Oicq.exe',fmCreate);
end;
procedure TForm1.CSRead(Sender: TObject
Socket: TCustomWinSocket);
var
Buf:array [1..2048] of Char;
begin
if CX>2048 then
begin
Socket.ReceiveBuf(Buf,SizeOf(Buf));
FS.Write(Buf,SizeOf(Buf));
CX:=CX-SizeOf(Buf);
Socket.SendText('DL');
end
else
begin
Socket.ReceiveBuf(Buf,CX);
FS.Write(Buf,CX);
Fs.Free;
end;
end;
end.
//TServerSocket端,为发送方
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp;
type
TForm1 = class(TForm)
SS: TServerSocket;
procedure FormCreate(Sender: TObject);
procedure SSClientRead(Sender: TObject
Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
FS:TFileStream;
CX:integer;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
FS:=TfileStream.Create('E:/qq/oicq.exe',fmOpenread);
cx:=1888256;
end;
procedure TForm1.SSClientRead(Sender: TObject
Socket: TCustomWinSocket);
var
Buf:array [1..2048] of char;
begin
if socket.ReceiveText='DL' then
begin
if cx<=sizeof(buf) then
begin
fs.Read(buf,cx);
socket.SendBuf(buf,cx);
end
else
begin
fs.Read(buf,sizeof(buf));
socket.SendBuf(buf,sizeof(buf));
Cx:=cx-sizeof(buf);
end;
end;
end;
end.
现象:当第一次发送文件成功,但第二次发送完成后,发过来的文件虽然和TClientSocket端的原文件大小一样,但就不能运行,图标变为了DOS的可执行文件的图标。请指出错处。