Solved

indy tcp extract data

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
My project did see openJDK that I installed. What could be the problem 7 142
VOB to mp3 8 74
Adjust the position 3 60
Tvertscrollbox like a whatsapp layout delete messages 1 16
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

772 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