Solved

indy tcp extract data

Posted on 2014-09-20
4
197 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
  • 2
4 Comments
 
LVL 26

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 26

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can Viruses spread while transferring Binary data with Winsock 2 66
sumDigits  challenge 7 74
WPF issue with Trigger 2 96
FMX and jaudiotracker playing memory stream 29 66
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…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now