Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 印地10号广播电台和AData_Delphi_Indy - Fatal编程技术网

Delphi 印地10号广播电台和AData

Delphi 印地10号广播电台和AData,delphi,indy,Delphi,Indy,我正在尝试通过indy udp组件进行文本聊天,下面是服务器和客户端的代码 udp客户端: procedure TForm1.SendClick(Sender: TObject); begin sendtocl.Broadcast(usertype.Text, 12000); usertype.Clear; end; onread服务器: procedure TForm1.UDPReceiverUDPRead(AThread: TIdUDPListenerThread; const AData

我正在尝试通过indy udp组件进行文本聊天,下面是服务器和客户端的代码

udp客户端:

procedure TForm1.SendClick(Sender: TObject);
begin
sendtocl.Broadcast(usertype.Text, 12000);
usertype.Clear;
end;
onread服务器:

procedure TForm1.UDPReceiverUDPRead(AThread: TIdUDPListenerThread; const AData: TIdBytes; ABinding: TIdSocketHandle);
var
  AudioDataSize: Integer;
  AudioData : Pointer;
begin
  try
    EnterCriticalSection(Section);
    try
      AudioDataSize := Length(AData);
      if AudioDataSize > 10 then
      begin
        try
          if not Player.Active then
          begin
            Player.Active := True;
            Player.WaitForStart;
          end;
        except
        end;
        if BlockAlign > 1 then Dec(AudioDataSize, AudioDataSize mod BlockAlign);
        AudioData := AudioBuffer.BeginUpdate(AudioDataSize);
        try
          BytesToRaw(AData, AudioData^, AudioDataSize);
        finally
          AudioBuffer.EndUpdate;
        end;
      end else
      begin
        Player.Active := False;
        Player.WaitForStop;
      end;
    finally
      LeaveCriticalSection(Section);
    end;
  except
  end;
begin
chatboxmsg.Lines.Add(BytesToString(AData));
  end;
end;
工作正常,但如果我将udp客户端用于发送缓冲区“发送音频”等其他用途,我会遇到问题。
chatboxmsg.line
以任何方式显示音频缓冲区的淹没数据,以使服务器读取分离的
Adata

在udp中,每次发送(
Broadcast()
send()
SendBuffer())
等)传输不同的数据报。对于接收到的每个数据报,都会触发
OnUDPRead
事件
AData
一次包含一个不同数据报的数据

因此,您有两个选择:

  • 以这样的方式格式化数据报(例如在数据的前面放一个标题),以便它们识别所携带的数据类型。这样,您的
    OnUDPRead
    处理程序就可以读取标识符/头,并知道是将剩余数据放入
    ChatBoxMsg
    还是将其传递给音响系统

  • 如果您不想(或不能)更改数据报格式,则必须将文本和音频数据报发送到不同的端口。您可以使用一个
    TIdUDPServer
    对象同时监听多个端口(这就是它的
    绑定
    集合的目的),在这种情况下,
    OnUDPServer
    事件的
    ABinding
    参数将告诉您在哪个端口上接收到
    AData
    。或者,只需使用两个独立的
    TIdUDPServer
    对象,每个对象监听不同的端口,并为每个对象分配不同的
    OnUDPRead
    处理程序


  • 欢迎来到堆栈溢出。要表示问题已解决,请选择解决问题的答案。如果您自己找到了另一个解决方案,请将该解决方案发布在“答案”部分,然后选择它。不要删除你问题的内容;它使现有的答案看起来像胡说八道。