TVirtualDrawtree

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

- You try to send them sequentially. Make a message queue. When user want to send a message, you add this message to the queue.
- Send button will be trigger a repeat / until loop process. In the loop, send the first message on the queue and delete the processesed message until the list is empty.
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

a little magic code example will help too much for better understand
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

Try this...

I have no time for try. But I trace with my eyes, this is what i say...

Just place a new TListBox to the form..

// This is class for MessageQueue Object...

Kod: Tümünü seç

  TMessageQueueObject = class(TObject)
    strSenNick : String;
    dwSenUID   : DWORD;
    strRecNick : String;
    dwRecUID   : DWORD;
    strMessage : String;
    MsgDateTime: TDateTime;
  end;
// This is Message Send Loop Mechanism

Kod: Tümünü seç

Var
  xboolMessageSendProcessContinues : Boolean;

procedure Ttestthreading.MessageSendProcess( ListBox : TListBox; MemoLog:TMemo; TCPClient: TIdTCPClient);
Var
  aMess : TMessageQueueObject;
begin
  xboolMessageSendProcessContinues := True;
    while ListBox.Count > 0 do
    begin
      aMess := TMessageQueueObject( ListBox.Items.Objects[0] );
      if SendCommandWithParams(TCPClient, 'TEXTMESSAGE', aMess.strSenNick + Sep + IntToStr(aMess.dwRecUID) + Sep) then
      begin
        MemoLog.Lines.Add('<' + aMess.strSenNick + '>' + aMess.strMessage );
        ListBox.Items.Delete(0);
      end;
      sleep(1);
      Application.ProcessMessages; 
    end; // while
  xboolMessageSendProcessContinues := False;
end;
// This is before and after changes section

Kod: Tümünü seç

procedure Ttestthreading.bSendClick(Sender: TObject);
Var
  Mess: TMessageQueueObject;
begin
  if (ListView1.Selected <> Nil) AND (edMessage.Text <> '') then
  begin
    Mess := TMessageQueueObject.Create;
    Mess.strSenNick  := edUser.Text;
    Mess.dwSenUID    := UniqueID;
    Mess.strRecNick  := ListView1.Selected.SubItems[0];
    Mess.dwRecUID    := StrToInt( ListView1.Selected.SubItems[3] );
    Mess.strMessage  := edMessage.Text;
    Mess.MsgDateTime := Now;
    ListBox1.AddItem( 'Mess:'+ DateTimeToStr(Mess.MsgDateTime), TObject(Mess) );
    if NOT xboolMessageSendProcessContinues then
    begin // This is trigger..
      MessageSendProcess( ListBox1, mMessage, TCPClient );
    end;

   // before above was only below... //
   / /mMessage.Lines.Add('<' + edUser.Text + '>' + edMessage.Text);
   // SendCommandWithParams(TCPClient, 'TEXTMESSAGE', edMessage.Text + Sep + ListView1.Selected.SubItems[3] + Sep);
  end;
end;
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

what i understand is send always name , message , id , channel id . is that correct ? yes i got this part also iam working on example now i will show it to you after i finish
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

that's what i did and what i stuck in ,

i created protocol i call it channelChange in server side ,

Kod: Tümünü seç

procedure TfMain.ChannelChange(const Channelvalue: String; const FromUniqueID: DWord; const FromName: string);
var
  I: Integer;
  Index_Room: Integer;
begin
  for Index_Room := 0 to Connections.Count -1 do
  begin
    if TConnection(Connections.Items[Index_Room]).UniqueID = FromUniqueID then
    begin
      Break;
    end;
  end;
  for I := 0 to Connections.Count - 1 do
  begin
    if ((TConnection(Connections.Items[I]).Channel = TConnection(Connections.Items[Index_Room]).Channel) and
        (TConnection(Connections.Items[I]).UniqueID <> FromUniqueID)) or
       (TConnection(Connections.Items[I]).Channel = strToint(Channelvalue)) then// then he send to others
    begin
      SendCommandWithParams(TConnection(Connections.Items[I]), 'Channel', FromName + Sep + Channelvalue + Sep + inTtostr(FromUniqueID) + Sep);
    end;
  end;
  TConnection(Connections.Items[Index_Room]).Channel := StrToint(Channelvalue);
  lwConnections.Items.Item[Index_Room].SubItems.Strings[3] := Channelvalue;
end;


its possibly bad idea i dont know you know best ,

also added new buttons channel 1 and channel 2 and created setter and getter for change channel id , my problem is i want to grab the list of connected client for each channel , as example send list of client where there channel id =1 or what ever here is my project
Dosya ekleri
newclienta.rar
(94.76 KiB) 77 kere indirildi
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

I see.. You want channeling for multi instance user logon purposes... I totally wrong understood.

In my opinion, you just add one more parameter for channel thing is ok. Nothing else need.

But I want to know, why you need multichannel operation like this, your client allready can open up two different user with different explorer thread.

If you plan to stream voice, image, video or something at the same time you will need one more TIdTCPClient with different port to use. You need to plan this today, not tomorrow... AND important thing you need to think about UDF instead of TCP for video/audio thing... Because TCP needs to know packets safely transferred so that block your channel until finish his work.
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

adding parameter with channel variable in which procedure ? about audio and video thing i used before send buffer command and used as example

Kod: Tümünü seç

procedure TServobj.BroadCastAudioMessage(const Buffer: TIdBytes;
  const BufferSize: Cardinal; const FromUniqueID: DWord);
var
 Index: Integer;
  Connection: TConnection;
  Index_Room: Integer;
begin
  for Index_Room := 0 to Connections.Count -1 do
  begin
    begin
      Break;
    end;
  end;
  for Index := 0 to Connections.Count - 1 do
  begin
    Connection := Connections.Items[Index];
    begin
  end;
  end;
end;
streaming works real good i cannot include it to this project because its used wave audio component that many possibly not installed with every body delphi

i just wana bring list for each channel now , so lets back to topic adding parameter in which procedure ? SendClientsList ?
En son mia tarafından 05 Haz 2015 12:48 tarihinde düzenlendi, toplamda 1 kere düzenlendi.
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

When you plan the Protocol thing, also you must plan about how many parameter you need.
This channel parameter must be all transactions I guess. Then every three procedure must have this parameter. So the server project must be ready by this option.

Other thing, the stream operation, the server must back / out between two client which talk. This means two client became between a mini server / mini client. This is more eficient for speed and latency. So ypu must plan to every client may be a server at the same time.

When the streaming issue neded, one client became a server and other client became the sub client. So the real server traffic will automatically reduces.

This is also very easy to do but hard to describe. Before you need to plan this traffic with a workflow. you must know when texting what to do, when streaming what to do ext. on the paper.
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

do you mean this procedure then

Kod: Tümünü seç

procedure TfMain.ChannelChange(const Channelvalue: String; const FromUniqueID: DWord; const FromName: string);
i already have channelvalue in channel change parameter and i already checked to send some change channel alert for current channel user only you can test it on client side , what i mean now the SendClientsList

Kod: Tümünü seç

procedure TServobj.SendClientsList;
var
  I: Integer;
  SL: TStringList;
  MS: TMemoryStream;
  Connection : TConnection;
begin
  SL := TStringList.Create;
  try
    // Collect List
    for I := 0 to Connections.Count - 1 do
    begin
      Connection := TConnection(Connections.Items[I]);
      SL.Add(Connection.Name + Sep + IntToStr(Connection.UniqueID) + Sep);
    end;

    // Send List
    for I := 0 to Connections.Count - 1 do
    begin
      Connection := TConnection(Connections.Items[I]);
      if (SL.Count > 0) then
      begin
        MS := TMemoryStream.Create;
        try
          SL.SaveToStream(MS);
          MS.Position := 0;
          SendCommandAndStream(Connection, 'GETLIST', MS);
          // SendStream(TheConnection, Ms);
        finally
          MS.Free;
        end;
      end;
    end;
  finally
    SL.Free;
  end;
end;

its sends all users in all channel i dont wana do this i just wana send all users in there channel like if there is 10 user in channel 1 so send client list will send users in channel 1 only not all users in other channels . do you get me
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

In short I mean, server must know, also client must know every messaging thread over which channel ... Thats all.

if client send it's message channel (n) answer must be use channel (n)
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

i try to do this

Kod: Tümünü seç

procedure TServobj.SendClientsListTo(const UniqueID: DWord);
var
  Index: Integer;
  Index_Room: Integer;
  SL: TStringList;
  MS: TMemoryStream;
  Connection,
  TheConnection: TConnection;
begin
  TheConnection := nil;
  SL := TStringList.Create;
  try
   for Index_Room := 0 to Connections.Count -1 do
  begin
    if TConnection(Connections.Items[Index_Room]).UniqueID = UniqueID then
    begin
      Break;
    end;
  end;
    for Index := 0 to Connections.Count - 1 do
    begin
      Connection := TConnection(Connections.Items[Index]);
    if  (Connection.Channel= TConnection(Connections[Index_Room]).Channel) then //all other clients
      begin
        SL.Add(Connection.Name + Sep + Connection.IP + Sep + FormatDateTime('hh:mm:ss', Connection.Connected) + Sep + IntToStr(Connection.UniqueID) + Sep + Connection.Channel+ Sep);
        if (Connection.UniqueID = UniqueID) then
        begin
          TheConnection := TConnection(Connections.Items[Index]);
        end;
   {  else
        TheConnection := Connection; //the client who is just connected    }
      end;
    end;
    if (SL.Count > 0)  and (TheConnection <> nil) then
    begin
      MS := TMemoryStream.Create;
      try
        SL.SaveToStream(MS);
        MS.Position := 0;
        SendCommandAndStream(TheConnection, 'GETLIST', MS);
        //SendStream(TheConnection, Ms);
      finally
        MS.Free;
      end;
    end;
  finally
    SL.Free;
  end;
end;
but it send to me only the client list in channel not broadcasting to every body else like the client list you did for change status and grab users what i did wrong ?
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

I'm sorry but I cannot figure out what you want to do ?
You already have this procedure before ?! :?
You just need to change the parameters policies. Why SendClientsListTo specified user, not all ? Client allready filter itself.

I think I wrote to much code to you. Because of this, you have very confused I gues... You need to make your own.
IMHO, I must stop a while code writing... :roll:
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

oh i didn't get realize of the break point i really been stupid too much , thank you mrmarman i figure out the problem , iam so stupid thank you very much . not your code who makes me confused iam some how stupid
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

i hope you not get bored from me :?

i stay all night try to do it and here where i come so far i uploaded the project iam able to grab the clients in current channel but iam unable to refresh clients when i change the channel ,, here is the project it has pitfalls i hope you helo me with it , note some times i get complicated from describe the problem because i always understand with codes
Dosya ekleri
newclienta.rar
(94.8 KiB) 72 kere indirildi
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

You want me a difficult thing.
From your code how to know what you need ? if I write my own code for you then you will fall deeper.

Now I make a look your (Channelling) setup but all code must be change for consistency. I don't see any rule work in your code.

For example :
Rule 1: Channel (0) covers all channels
Rule 2: All sendmessage things must be same protocol like

Kod: Tümünü seç

    // Param 0 CONST always Channel Number
    // Param 1 CONST always Sender UniqueID
    // Param 2 VAR   Message Text depend on TEXTMESSAGE depend on client to client or server to client
    // Param 3 CONST always Receiver UniqueID 
    // Param 4 VAR   Receiver IP depend on client to client or server to client
    // Param 5 VAR   ext.ext.
Rule 3: If any client became a server while streaming, the protocol changes to any other.
ext.ext.
Resim
Resim ....Resim
Cevapla