kodları da şöyle
server.pas
Kod: Tümünü seç
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ImgList, ComCtrls, Menus, ScktComp,IniFiles, StdCtrls;
type
drm=(acik=0,acikOK=1,sureli=2,sureliOK=3,
hspkapat=4,hspkapatOK=5,ekrangoruntu=6,ekrangoruntuOK=7);
type
TForm1 = class(TForm)
ListView1: TListView;
ImageList1: TImageList;
PopupMenu1: TPopupMenu;
AkHesap1: TMenuItem;
SreliHesap1: TMenuItem;
HesapKapat1: TMenuItem;
Server1: TServerSocket;
N1: TMenuItem;
BilgisayarYenidenBalat1: TMenuItem;
BilgisayarKapat1: TMenuItem;
N2: TMenuItem;
HesapBilgisiAl1: TMenuItem;
Memo1: TMemo;
Button1: TButton;
Memo2: TMemo;
EkranGrntsAl1: TMenuItem;
procedure AkHesap1Click(Sender: TObject);
procedure ListView1ContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
procedure FormCreate(Sender: TObject);
procedure Server1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure Server1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure Button1Click(Sender: TObject);
procedure Server1ClientRead(Sender: TObject; Socket: TCustomWinSocket);
function hangiclient(sckt:TCustomWinSocket):integer;
procedure SreliHesap1Click(Sender: TObject);
procedure islemyap(Sckt: TCustomWinSocket);
procedure HesapKapat1Click(Sender: TObject);
procedure EkranGrntsAl1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
str:string;
Ini: TIniFile;
baglanti:array of integer;
bagli:integer;
clientler:TStringList;
durum:drm;
implementation
uses unit2;
{$R *.dfm}
procedure TForm1.AkHesap1Click(Sender: TObject);
var cvp:integer;
begin
cvp:=MessageDlg( ListView1.Selected.Caption+' için açık hesap açmak istiyor musunuz ?',
mtConfirmation,mbOKCancel,0);
if cvp=mrOK then
begin
durum:=acik;
server1.Socket.Connections[baglanti[ ListView1.Selected.Index]].SendBuf(durum,sizeof(durum));
end;
end;
procedure TForm1.ListView1ContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
begin
if ListView1.SelCount>0 then
ListView1.PopupMenu:=PopupMenu1
else
ListView1.PopupMenu:=nil;
end;
procedure TForm1.FormCreate(Sender: TObject);
var adet,i:integer;
cl:string;
begin
ini:=TIniFile.Create(ChangeFileExt(Application.ExeName,'.INI'));
adet:=ini.ReadInteger('GENEL','PCADET',0);
setlength(baglanti,adet);
clientler:=TStringList.Create;
for i:=0 to adet-1 do
begin
cl:=ini.ReadString('PCADLARI','MASA'+inttostr(i+1),'');
ListView1.Items.Item[i].Caption:=cl;
clientler.Add(cl);
end;
Server1.Active:=true;
Server1.Open;
bagli:=0;
end;
procedure TForm1.Server1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
var indx:integer;
begin
indx:=hangiclient(Socket);
//ListView1.Items.Item[j-1].Caption:='Masa '+inttostr(j)+
// #13#10+'('+Socket.RemoteHost+')';
ListView1.Items.Item[indx].ImageIndex:=1;
baglanti[indx]:=bagli;
bagli:=bagli+1;
ShowMessage(Socket.RemoteHost+' bağlandı');
end;
procedure TForm1.Server1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
ListView1.Items.Item[hangiclient(Socket)].ImageIndex:=0;
ShowMessage(Socket.RemoteHost+' ile bağlantı koptu');
bagli:=bagli-1;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Server1.Socket.Connections[0].SendText(Memo1.Text);
//Server1.Socket.SendText('ok');
end;
procedure TForm1.Server1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
islemyap(Socket);
end;
function TForm1.hangiclient(sckt: TCustomWinSocket): integer;
begin
Result:=clientler.IndexOf(sckt.RemoteHost);
end;
procedure TForm1.SreliHesap1Click(Sender: TObject);
var cvp:integer;
begin
cvp:=MessageDlg( ListView1.Selected.Caption+' için süreli hesap açmak istiyor musunuz ?',
mtConfirmation,mbOKCancel,0);
if cvp=mrOK then
begin
durum:=sureli;
server1.Socket.Connections[baglanti[ ListView1.Selected.Index]].SendBuf(durum,sizeof(durum));
end;
end;
procedure TForm1.islemyap(Sckt: TCustomWinSocket);
var bmp:TBitmap;
begin
sckt.ReceiveBuf(durum,sizeof(durum));
case durum of
acikOK:ListView1.Items.Item[hangiclient(Sckt)].ImageIndex:=2;
sureliOK:ListView1.Items.Item[hangiclient(Sckt)].ImageIndex:=3;
hspkapatOK:ListView1.Items.Item[hangiclient(Sckt)].ImageIndex:=1;
ekrangoruntuOK: begin
bmp:=TBitmap.Create;
Sckt.ReceiveBuf(bmp,sizeof(bmp));
bmp.SaveToFile(sckt.RemoteHost+'.bmp');
Form2.resimyukle(sckt.RemoteHost+'.bmp');
Form2.ShowModal;
end;
else
memo2.Lines.Add(sckt.ReceiveText);
end;
end;
procedure TForm1.HesapKapat1Click(Sender: TObject);
var cvp:integer;
begin
cvp:=MessageDlg( ListView1.Selected.Caption+' hesabını kapatmak istiyor musunuz ?',
mtConfirmation,mbOKCancel,0);
if cvp=mrOK then
begin
durum:=hspkapat;
server1.Socket.Connections[baglanti[ ListView1.Selected.Index]].SendBuf(durum,sizeof(durum));
end;
end;
procedure TForm1.EkranGrntsAl1Click(Sender: TObject);
var cvp:integer;
begin
cvp:=MessageDlg( ListView1.Selected.Caption+' ekran görüntüsünü almak istiyor musunuz ?',
mtConfirmation,mbOKCancel,0);
if cvp=mrOK then
begin
durum:=ekrangoruntu;
server1.Socket.Connections[baglanti[ ListView1.Selected.Index]].SendBuf(durum,sizeof(durum));
end;
end;
end.
client.pas
Kod: Tümünü seç
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls;
type
drm=(acik=0,acikOK=1,sureli=2,sureliOK=3,
hspkapat=4,hspkapatOK=5,ekrangoruntu=6,ekrangoruntuOK=7);
type
TForm1 = class(TForm)
Client1: TClientSocket;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
Button3: TButton;
Memo2: TMemo;
procedure Button1Click(Sender: TObject);
procedure Client1Connect(Sender: TObject; Socket: TCustomWinSocket);
procedure Button2Click(Sender: TObject);
procedure Client1Disconnect(Sender: TObject; Socket: TCustomWinSocket);
procedure Client1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure Button3Click(Sender: TObject);
procedure islemyap(Sckt: TCustomWinSocket);
function getscreenshot():TBitmap;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
durum:drm;
ekran:TBitmap;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Client1.Host:='hakan';
Client1.Active:=true;
end;
procedure TForm1.Client1Connect(Sender: TObject; Socket: TCustomWinSocket);
begin
showmessage('client bağlanıyor');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Client1.Active:=false;
end;
procedure TForm1.Client1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
showmessage('client kopuyor');
end;
procedure TForm1.Client1Read(Sender: TObject; Socket: TCustomWinSocket);
begin
//memo2.Lines.Add( socket.ReceiveText+' komutu alındı');
islemyap(Socket);
//ShowMessage(socket.ReceiveText);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Client1.Socket.SendText(memo1.Text);
end;
procedure TForm1.islemyap(Sckt: TCustomWinSocket);
begin
Sckt.ReceiveBuf(durum,sizeof(durum));
case durum of
acik: begin
memo2.Lines.Add('açık hesap açıldı');
durum:=acikOK;
Client1.Socket.SendBuf(durum,sizeof(durum));
end;
sureli: begin
memo2.Lines.Add('süreli hesap açıldı');
durum:=sureliOK ;
Client1.Socket.SendBuf(durum,sizeof(durum));
end;
hspkapat: begin
memo2.Lines.Add('hesap kapatıldı');
durum:=hspkapatOK;
Client1.Socket.SendBuf(durum,sizeof(durum));
end;
ekrangoruntu:begin
ekran:= getscreenshot;
durum:=ekrangoruntuOK;
Client1.Socket.SendBuf(durum,sizeof(durum));
Client1.Socket.SendBuf(ekran,sizeof(ekran));
end;
else
memo2.Lines.Add(sckt.ReceiveText);
end;
end;
function TForm1.getscreenshot: TBitmap;
var
Desktop:HDC;
begin
Result:= TBitmap.Create;
Desktop:= GetDC(0);
try
try
Result.PixelFormat:=pf32bit;
Result.Width:=Screen.Width;
Result.Height:=Screen.Height;
BitBlt(Result.Canvas.Handle,0,0,Result.Width,Result.Height,Desktop,0,0,SRCCOPY);
Result.Modified:=True;
finally
ReleaseDC(0,Desktop);
end;
except
Result.Free;
Result:=nil;
end;
end;
end.
client server yapısıyla yeni tanıştığım için şimdilik sadece iletişimi görme açısından yazı yazdırmakla yetiniyorum.
şimdi bu yapıya göre clientin ekran resmini almaya çalışıyorum. ama dosyayı nasıl göndereceğimi bilemedim. forumda bi kaç mesaj buldum ama benim yapıya uyduramadım bi türlü.
sizce ne yapmalıyım