Solved

indy tcp extract data

Posted on 2014-09-20
4
204 Views
Last Modified: 2014-09-29
iam trying to create chat app thats support voice and text

i don with the codes but i stick on errors

i send audio stream like that

procedure Tmain.recorderData(Sender: TObject; const Buffer: Pointer;
  BufferSize: Cardinal; var FreeIt: Boolean);
  //user send audio how to send and recive ?
var
  Bytes: TIdBytes;
begin
  Freeit := True;
  if Tcli.Connected then
  begin
    if (Buffer <> nil) and (Buffersize > 0) then
    begin
      try
        Bytes := RawToBytes(Buffer^, Buffersize);
      except
        micstop.Caption := 'Invalid !';
        Exit;
      end;
      begin
      Tcli.IOHandler.Write(BufferSize);
      Tcli.IOHandler.Write(Bytes);
    end;
    end
     else
stop.Caption := 'Server error!';
  end else
    stop.Caption := 'Not connected';
end;

Open in new window


and server execute like this

procedure Tmain.TservExecute(AContext: TIdContext);
var
  AudioDataSize: Integer;
  AudioDataBytes: TIdBytes;
  AudioData : Pointer;
begin
try
    EnterCriticalSection(Section);
    try
      AudioDataSize := AContext.Connection.IOHandler.ReadLongInt();
      AContext.Connection.IOHandler.ReadBytes(AudioDataBytes, AudioDataSize);
      if AudioDataSize > 10 then
      begin
        if AudioDataSize <> 0 then
      begin
        try
          if not main.Player.Active then
          begin
            main.Player.Active := True;
            main.Player.WaitForStart;
          end;
        except
        end;
        if BlockAlign > 1 then
          Dec(AudioDataSize, AudioDataSize mod BlockAlign);
        AudioData := AudioBuffer.BeginUpdate(AudioDataSize);
        try
          BytesToRaw(AudioDataBytes, AudioData^, AudioDataSize);
        finally
          AudioBuffer.EndUpdate;
        end;
      end else
      begin
        Player.Active := False;
        Player.WaitForStop;
      end;
      end;
    finally
      LeaveCriticalSection(Section);
    end;
  except
    on e: exception do showmessage(e.Message)
  end;
end;

Open in new window


it works fine but now i cant read what user type in server execute when i use the both code

procedure Tmain.SendClick(Sender: TObject);
//user send message but how to recive ?
var
  strMsg: string;
begin
if usertype.Text = '' then Abort;
strMsg := usertype.Text;
Tcli.IOHandler.WriteLn(strMsg);
usertype.Clear;
end;

Open in new window



any idea on how extract and read audio data and text together ? i search alot with no real help.
0
Comment
Question by:drama22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 40335491
You should make send buffer header - where you can describe what is following after....
My example of header:
type
  TBuffType = (btAudio, btChat);
  TChatHeader = record
    HeaderMagicCode: Integer;
    BufferType: TBuffType;
    BuffSize: Integer;
  end;

Open in new window


 HeaderMagicCode is a special value (like 999999) - useful when you go out of sync (when stream broke),
BufferType := btAudio when you send audio buffer with size: BuffSize.

When you detect (on server side) using BufferType = btAudio - buffer is audio, and if  BufferType = btChat - then it is chat text.
0
 

Author Comment

by:drama22
ID: 40335559
But that will broke text while other client's is talking its multiple user chatroom also I dont understand how to do it with my current code that I post it
0
 
LVL 27

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 40350890
That will not broke (chat) text. This header can contain destination address, block type (audio, text), size,... Server and client after that will know what is going on.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tidtcpserver connection lost handle 2 111
Excel file not created as expected 7 94
Delphi, TImage, Png 2 32
Delphi android app hide keyboard 3 47
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This video teaches viewers about errors in exception handling.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question