kızılötesi konusunda fazla bir bilgim yok. Ama bahsettiğin uygulamanın bluetooth ve Wireless ile çalışanlarını gördüm. Bütün olay ağ bağlantısında. Yani sen nasıl olursa olsun network olayını aşıp bilgisayar ve diğer cihazlar arasında bağlantı kurduğunda işi çözmüş oluyorsun. Geriye sadece cihazları konuşturmak için oluşturacağın özel bir protokol yazmak kalıyor.
Bende fırsat bulduğumda bu kızılötesi bağlantıyla ilgili bir araştırma yapayım. Bu bölümde benim bir client/server uygulama örneğim vardı. TCP/IP protokolleriyle birlikte kendi tanımladığım Kendine özgü bir özel protokol deklarasyonu içeriyordu... Mantık yönünden inceleyebilmen için bir bölümünü aşağıya ekliyorum...
PHP Kodu:
type
{ TCliStatus = csIdle : Dinlemede
csCONN : Bağlantı Kuruldu
csDRVL : Sürücü Listesi
csFOLD : Klasör Listesi
csList : Dosya Listesi
csCDRV : Sürücü Değiştirildi
csCDIR : Klasör Değiştirildi
csEmpt : Klasörde dosya yok
csBitmap : Bitmap Resim
csDesk : Masa üstü görünütüsü
csFCPY : Dosya kopyalama
csSCFN : Dosya Gönderme
csSize : Dosya/klasör boyu
csText : Text dosyası
csSTATU : Statü Mesajları...
csPath : Sunucu üzerinde geçerli path
csCOMM : Masa üstünde tıklama olayları
csTest : Test Ediliyor
csEnum : Açık uygulamalrın listesi, Text olarak gönderiliyor.
csChat : Chat
csError : Hata Mesajı;}
TCliStatus = (csIdle, csCONN,csDRVL,csFOLD,csList, csCDRV, csCDIR,csEmpt,
csBitmap, csDesk,csFCPY,csSCFN,csSize, csStatu,csPath, csText,csCommand ,
csEnum,csChat,csTest,csError);
Bu protokol mesajları istemciden gönderiliyor. Buna karşılık sunucu tarafı aşağıdaki işlemleri yapıyor...
//************************************************** ****************************//
{ CLIENT SOCKET SERVER READ YÖNTEMİ }
//************************************************** ***************************//
PHP Kodu:
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
FeedBack,strIn: string;
Stream : TMemoryStream;
FStream : TFileStream;
X,Y,nReceived : Integer;
Jpg : TJpegImage;
begin
case CliStatus of
csIdle:
begin
Socket.ReceiveBuf (Buffer, 5);
strIn := Copy (Buffer, 1, 5);
if strIn = 'TEXT!' then
CliStatus := csText
else if strIn = 'BITM!' then
CliStatus := csBitmap
else if strIn = 'LIST!' then
CliStatus := csList
else if strIn = 'CONN!' then
CliStatus := csCONN
else if strIn = 'DRVL!' then
CliStatus := csDRVL
else if strIn = 'FOLD!' then
CliStatus := csFOLD
else if strIn = 'CDRV!' then
CliStatus := csCDRV
else if strIn = 'CDIR!' then
CliStatus := csCDIR
else if strIn = 'EMPT!' then
CliStatus := csEmpt
else if strIn = 'DESK!' then
CliStatus := csDesk
else if strIn = 'FCPY!' then
CliStatus := csFCPY
else if strIn = 'SIZE!' then
CliStatus := csSize
else if strIn = 'SCFN!' then
CliStatus := csSCFN
else if strIn = 'STAT!' then
CliStatus := csStatu
else if strIn = 'TEST!' then
CliStatus := csTest
else if strIn = 'COMM!' then
CliStatus := csCommand
else if strIn = 'PATH!' then
CliStatus := csPath
else if strIn = 'ENUM!' then
CliStatus := csEnum
else if strIn = 'CHAT!' then
CliStatus := csChat
else if strIn = 'ERROR' then
CliStatus := csError;
end;
//Dosya/klasör boyu alınıyor
csSize:
Begin
cliStatus := csIdle;
strIn := Socket.ReceiveText;
AddMemoMsg(strIn,1);
End;
//Masa üstünde tıklama olayına cevap veriliyor.
csCommand :
Begin
cliStatus := csIdle;
strIn := Socket.ReceiveText;
if Assigned(FormBmp) Then FormBmp.Hint :=strIn+' - Yerel Zaman :'+TimeToStr(Time);
AddMemoMsg('Masa üstü görüntüsü istendi.',0);
ClientSocket1.Socket.SendText ('DESK!');
End;
// show the messages (might actually not be an error)
csError:
begin
AddMemoMsg(Socket.ReceiveText,1);
cliStatus := csIdle;
end;
//Yapılan işlemle ilgili sonuç mesajı gönderildiyse
csStatu :
Begin
AddMemoMsg(Socket.ReceiveText,1);
cliStatus := csIdle;
//Klasör Listesini iste oda dosya listesini günceller.
Socket.SendText('FOLD!');
end;
//Sunucu üzerindeki tam yol adı
csPath:
begin
FCurPath := Socket.ReceiveText;
AddMemoMsg('Sunucu yolu :'+FCurPath,1);
LabelDir.Caption := FCurPath;
cliStatus := csIdle;
end;
// bağlantı bilgisini kaydet
csCONN:
begin
//AddMemoMsg('Bağlantı kuruldu.');
strIn :=Socket.ReceiveText;
AddMemoMsg(strIn,1);
CliStatus := csIdle;
//Sürücü Listesini iste
ClientSocket1.Socket.SendText('DRVL!');
AddMemoMsg('Sürücü listesi istendi.',0);
Caption := EditServer.Text+' Bağlı.[ '+GetKaynak(strIn)+'-'+GetHedef(strIn)+' ]';
end;
// Sürücü listesini al
csDRVL:
Begin
ComboBox1.Items.Text :=(Socket.ReceiveText);
CliStatus := csIdle;
//Klasör Listesini iste
ClientSocket1.Socket.SendText('FOLD!');
AddMemoMsg('Klasör listesi istendi.',0);
end;
csFOLD:
Begin
ListBox1.Items.Text := (Socket.ReceiveText);
CliStatus := csIdle;
//Dosya listesini iste
ClientSocket1.Socket.SendText ('LIST!');
AddMemoMsg('Dosya listesi istendi.',0);
End;
//Sürücü Değiştiyse
csCDRV:
Begin
AddMemoMsg(Socket.ReceiveText,1);
CliStatus := csIdle;
//Klasör Listesini iste
ClientSocket1.Socket.SendText('FOLD!');
AddMemoMsg('Sürücü değişikliğinden klasör listesi istendi.',0);
End;
//Klasör değiştiyse
csCDIR:
Begin
AddMemoMsg(Socket.ReceiveText,1);
CliStatus := csIdle;
//Dosya listesini iste
ClientSocket1.Socket.SendText ('LIST!');
AddMemoMsg('Klasör değişikliğinden dosya listesi istendi.',0);
End;
// get a directory listing
csList:
begin
ListBox2.Items.Text := Socket.ReceiveText;
TabSheet1.Caption := 'Dosya Sistemi - ' + GetListelenenKlasor(0);
cliStatus := csIdle;
AddMemoMsg('Dosya listesi alındı.',2);
//Sunucu Aktif Yolunu İste.
AddMemoMsg('Sunucu aktif yolu istendi.',0);
Socket.SendText('PATH!');
end;
//Dosya bulanamadı mesajı alırsan
csEmpt:
begin
ListBox2.Items.Text := Socket.ReceiveText;
LabelDir.Caption := GetListelenenKlasor(0);
cliStatus := csIdle;
//Klasör Listesini iste
ClientSocket1.Socket.SendText('FOLD!');
AddMemoMsg('Dosya bulanamadığından klasör listesi yeniden istendi.',0);
end;
//Açık uygulama listes
csEnum:
begin
AddMemoMsg('Text dosyası alındı.',1);
with TFormText.Create (Application) do
begin
Memo1.Text := Socket.ReceiveText;
if Assigned(FormMetin) Then
Begin
FormMetin.ComboBoxApp.Items.Assign(Memo1.Lines);
FormMetin.ComboBoxApp.ItemIndex := 0;
end else Show;
end;
cliStatus := csIdle;
end;
// read a text file
csText:
begin
AddMemoMsg('Text dosyası alındı.',1);
with TFormText.Create (Application) do
begin
Memo1.Text := Socket.ReceiveText;
Show;
end;
cliStatus := csIdle;
end;
// Dosya al
csFCPY:
Begin
AddMemoMsg('Dosya indiriliyor.',1);
FStream := TFileStream.Create(FFileName, fmCreate or fmShareDenyWrite);
Screen.Cursor := crHourglass;
try
while True do
begin
nReceived := Socket.ReceiveBuf (Buffer, sizeof (Buffer));
if nReceived <= 0 then
Break
else
FStream.Write (Buffer, nReceived);
// delay (200 milliseconds)
Sleep (200);
end;
// reset and load the temporary file
FStream.Position := 0;
finally
FStream.Free;
Screen.Cursor := crDefault;
cliStatus := csIdle;
AddMemoMsg(FFileName+' yerel bilgisayara kopyalandı.',1);
end;
end;
//Dosya gönderilebilir mesajı aldıysan
csSCFN:
Begin
AddMemoMsg(Socket.ReceiveText,1);
cliStatus := csIdle;
End;
// Masa üstü görünütüsünü al
csDesk:
begin
if Not Assigned(FormBmp) Then FormBmp := TFormBmp.Create (Application);
FormBmp.Image1.Picture := Nil;
with FormBmp do
begin
FDeskCounter := Tag;
Inc(FDeskCounter);
Caption := 'Resim :'+IntToStr(FDeskCounter);
AddMemoMsg('Masa üstü görüntüsü yükleniyor...',1);
Jpg := TJpegImage.Create;
Stream := TMemoryStream.Create;
Screen.Cursor := crHourglass;
try
while True do
begin
nReceived := Socket.ReceiveBuf (Buffer, sizeof (Buffer));
if nReceived <= 0 then
Break
else
Stream.Write (Buffer, nReceived);
// delay (200 milliseconds)
Sleep (200);
end;
// reset and load the temporary file
Stream.Position := 0;
Jpg.LoadFromStream(Stream);
Image1.Picture := Nil;
Image1.Picture.Assign(JPG);
finally
Stream.Free;
Screen.Cursor := crDefault;
end;
Show;
cliStatus := csIdle;
end;
end;
//Test Edildi mesajı
csTest :
Begin
AddMemoMsg(Socket.ReceiveText,1);
cliStatus := csIdle;
End;
csChat :
Begin
if Not Assigned(FSocketMsg) Then FSocketMsg := TFSocketMsg.Create(Self);
FSocketMsg.WindowState := wsNormal;
FSocketMsg.Show;
End;
// read a bitmap file
csBitmap:
with TFormBmp.Create (Application) do
begin
Stream := TMemoryStream.Create;
Screen.Cursor := crHourglass;
try
while True do
begin
nReceived := Socket.ReceiveBuf (Buffer, sizeof (Buffer));
if nReceived <= 0 then
Break
else
Stream.Write (Buffer, nReceived);
// delay (200 milliseconds)
Sleep (200);
end;
// reset and load the temporary file
Stream.Position := 0;
Image1.Picture.Bitmap.LoadFromStream (Stream);
finally
Stream.Free;
Screen.Cursor := crDefault;
end;
Show;
cliStatus := csIdle;
end;
end; // case
end;