server端
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, ExtCtrls, StdCtrls;
type
TForm2 = class(TForm)
Button2: TButton;
Label1: TLabel;
ServerSocket1: TServerSocket;
Label2: TLabel;
Label3: TLabel;
Image1: TImage;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
buf:Array[0..1023] of char;
stm:TMemoryStream;
implementation
{$R *.DFM}
procedure TForm2.FormCreate(Sender: TObject);
begin
serversocket1.Active:=true;
stm:=TMemoryStream.Create;
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
stm.Position:=0;
image1.Picture.Bitmap.LoadFromStream(stm);
end;
procedure TForm2.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
stm.SaveToFile('c:/lpp.bmp');
end;
procedure TForm2.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
socket.ReceiveBuf(buf,1024);
stm.Write(buf,1024);
end;
end.
clientsocket端
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
ClientSocket1: TClientSocket;
Button1: TButton;
Button2: TButton;
Image1: TImage;
Button3: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
buf:Array[0..1023] of char;
stm:TMemoryStream;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
stm:=TMemoryStream.Create;
stm.LoadFromFile('c:/windows/clouds.bmp');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
clientsocket1.Address:='172.18.128.182';
clientsocket1.Active:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
clientsocket1.Socket.SendStream(stm);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
clientsocket1.Active:=false;
end;
end.