Solved

indy tcp extract data

Posted on 2014-09-20
4
208 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

717 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