cnt
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, ComCtrls, StdCtrls;
type
TMainForm = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
StatusBar: TStatusBar;
OpenDialog: TOpenDialog;
ClientSocket: TClientSocket;
Memo: TMemo;
Edit: TEdit;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure EditChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
Const
BufLen:Integer=30*1024;
Type
Buffer=Array[1..1] of Byte;
Var
MemStream:TMemoryStream;
Fin:File;
Buf:^Buffer;
Temp:Longint;
Code:Integer;
s,s1:String;
procedure TMainForm.Button1Click(Sender: TObject);
begin
ClientSocket.Port:=3366;
ClientSocket.ClientType:=ctNonBlocking;
ClientSocket.Address:='127.0.0.1';
ClientSocket.Open;
StatusBar.SimpleText:='Socket open!';
end;
procedure TMainForm.Button3Click(Sender: TObject);
begin
ClientSocket.Close;
StatusBar.SimpleText:='Socket closed!';
end;
procedure TMainForm.Button2Click(Sender: TObject);
Var
sending,sent:Longint;
index:Longint;
begin
If OpenDialog.Execute Then
Begin
Memo.Clear;
GetMem(Buf,BufLen);
AssignFile(Fin,OpenDialog.FileName);
Try
Reset(Fin,1);
BlockRead(Fin,Buf^,BufLen,Temp);
Str(temp,s);
sent:=0;
Index:=1;
StatusBar.SimpleText:='File senting!';
While Temp>0 do
Begin
While sent<temp do
Begin
sending:=ClientSocket.Socket.SendBuf(Buf^[index],Temp);
If sending<>-1 Then
Begin
sent:=sent+sending;
index:=index+sending;
temp:=temp-sending;
End;
End;
Str(sent,s1);
Memo.Lines.Add('Read:'+s+' Send:'+s1);
BlockRead(Fin,Buf^,BufLen,Temp);
sent:=0;
Index:=1;
Str(temp,s);
End;
Finally
CloseFile(Fin);
FreeMem(Buf);
End;
End;
StatusBar.SimpleText:='File send!';
end;
procedure TMainForm.EditChange(Sender: TObject);
begin
Val(Edit.Text,BufLen,Code);
Str(BufLen,s);
Label1.Caption:=s;
end;
end.