1
我一直在使用印UDP,我想移动到印TCP转换自印UDP协议TCP
,但我不知道如何代码以同样的方式与印TCP工作转换
我的项目工作流发送这里聊天室是udp的代码
procedure TForm1.recorderData(Sender: TObject; const Buffer: Pointer;
BufferSize: Cardinal; var FreeIt: Boolean);
begin
Freeit :=True;
if IDUDPCLIENT.active then
IDUDPCLIENT.SendBuffer(RawToBytes(Buffer^, Buffersize))
else
stop.Caption := 'error';
end;
,这是读事件的服务器
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;
end;
我如何让他们在indy tcp以相同的方式工作?
谢谢雷米这就是对我很有帮助。 – DelphiStudent 2014-09-10 20:01:36
还有一件事雷米iam试图发送udp消息我正在这样做iDCLIENT.Broadcast(strMsg,16000);并读取像这样msg.Lines.Add(BytesToString(AData));如何在tcp中做到这一点? – DelphiStudent 2014-09-11 00:34:41
TCP不支持广播。您必须将您的消息数据的单独副本发送给您拥有的每个单独的TCP连接。 – 2014-09-11 16:53:27