Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: listening on multi port in Idudpserver


This question is answered.


Permlink Replies: 21 - Last Post: Jan 4, 2018 12:56 PM Last Post By: Remy Lebeau (Te...
madammar ellias

Posts: 111
Registered: 8/17/17
listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 19, 2017 9:18 PM
i am trying to listen on multiable ports into my server but i am wondering should i create a new server app for each port ? or i can make my app listen and communicate to several ports at the same time in one app ?
procedure Tudpservfrm.UpdateBindings;
var
Binding: TIdSocketHandle;
begin
udpserver.DefaultPort := StrToInt(Edit1.Text);
udpserver.Bindings.Clear;
Binding := udpserver.Bindings.Add;
Binding.IP := '0.0.0.0';
Binding.Port := StrToInt(Edit1.Text);
end;
 
procedure Tudpservfrm.udpserverUDPRead(AThread: TIdUDPListenerThread;
  const AData: TIdBytes; ABinding: TIdSocketHandle);
var
I : integer;
datastring, command : string;
Node: PVirtualNode;
Data: PUserData;
Nodesend: PVirtualNode;
Datasend: PUserData;
begin
datastring := bytestostring(AData);
command := copy(datastring,1,pos('~',datastring)-1);//parse
 
 
if command = 'login' then
begin
TThread.Synchronize(nil,
procedure
begin
Add_item(ABinding.PeerIP, ABinding.PeerPort, ABinding.Port);
end);
 
end else
 
if command = 'logout' then
begin
TThread.Synchronize(nil,
procedure
begin
Node := lookingTreeView(vdt1, ABinding.PeerIP, ABinding.PeerPort, ABinding.Port);
Data := VDT1.GetNodeData(Node);
 
if Node <> nil then
begin
VDT1.DeleteNode(Node);
end;
end);
end else
begin
TThread.Synchronize(nil,
procedure
begin
 
Nodesend := Vdt1.GetFirst();
 
while Nodesend <> nil do
begin
Datasend := vdt1.GetNodeData(Nodesend);
 
if (Datasend.FObject.aserverport = ABinding.Port)
And (Datasend.FObject.portnum <> ABinding.PeerPort) then
begin
Abinding.SendTo(Datasend.FObject.ipaddr, Datasend.FObject.portnum, Adata);
end;
 
Nodesend := vdt1.GetNext(Nodesend);
end;
end);
end;
 
 
end; 
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 20, 2017 11:05 AM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:

i am trying to listen on multiable ports into my server but i am
wondering should i create a new server app for each port ?

That is not necessary. TIdUDPServer has a Bindings property. You can
add a separate entry to it for each IP/Port you want to listen on. The
OnUDPRead event will tell you which entry a packet was received with.

or i can make my app listen and communicate to several ports at the
same time in one app ?

Of course you can.

--
Remy Lebeau (TeamB)
madammar ellias

Posts: 111
Registered: 8/17/17
Re: listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 20, 2017 11:50 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Of course you can.

--
Remy Lebeau (TeamB)

i can understand the part of adding more binding something like
Binding := udpserver.Bindings.Add;
Binding.IP := '0.0.0.0';
Binding.Port := more ports;


but is the udpserver will communicate only with specific port or i have to define it in the onread ?
also should i need to restart the server each time adding new port ?
madammar ellias

Posts: 111
Registered: 8/17/17
Re: listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 21, 2017 1:44 AM   in response to: madammar ellias in response to: madammar ellias
i have added about 60 ports all works well but i have a very high cpu when more than 10 clients subscribed
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 21, 2017 10:12 AM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:

i have added about 60 ports all works well

Why do you need so many ports?

i have a very high cpu when more than 10 clients subscribed

There is no subscription in TIdUDPServer. And I can't imagine 10
clients are sending so much traffic to peg the CPU.

--
Remy Lebeau (TeamB)
madammar ellias

Posts: 111
Registered: 8/17/17
Re: listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 21, 2017 10:19 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
madammar ellias wrote:

i have added about 60 ports all works well

Why do you need so many ports?

i have a very high cpu when more than 10 clients subscribed

There is no subscription in TIdUDPServer. And I can't imagine 10
clients are sending so much traffic to peg the CPU.

--
Remy Lebeau (TeamB)

i needed many ports because each channel i have should have separated data to be received i have about 100 channel
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 21, 2017 10:45 AM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:

i needed many ports because each channel i have should have
separated data to be received i have about 100 channel

But why not use fewer ports and just differentiate channels by sender
IP/Port or even packet data?

--
Remy Lebeau (TeamB)
madammar ellias

Posts: 111
Registered: 8/17/17
Re: listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 21, 2017 11:02 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
madammar ellias wrote:

i needed many ports because each channel i have should have
separated data to be received i have about 100 channel

But why not use fewer ports and just differentiate channels by sender
IP/Port or even packet data?

--
Remy Lebeau (TeamB)

to be honest i don't know how to do that exactly
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 21, 2017 1:18 PM   in response to: madammar ellias in response to: madammar ellias
Am 21.12.2017 um 20:02 schrieb madammar ellias:
Remy Lebeau (TeamB) wrote:
madammar ellias wrote:

i needed many ports because each channel i have should have
separated data to be received i have about 100 channel

But why not use fewer ports and just differentiate channels by sender
IP/Port or even packet data?

--
Remy Lebeau (TeamB)

to be honest i don't know how to do that exactly

Sender sends an UDP packet which includes the number of the channel as
payload. In the receive event you get the IP/port of the client
requesting a stream and as contents of the data packet you get the
channel number.

You then just need a list to keep track of this data.

Greetings

Markus
madammar ellias

Posts: 111
Registered: 8/17/17
Re: listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 21, 2017 1:48 PM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:

Sender sends an UDP packet which includes the number of the channel as
payload. In the receive event you get the IP/port of the client
requesting a stream and as contents of the data packet you get the
channel number.

You then just need a list to keep track of this data.

Greetings

Markus

the server code is fully added which show that i have a list using virtualstringtree what i dont know is how to inject the channel number to the audio bufferand read the channel number in server

Edited by: madammar ellias on Dec 21, 2017 1:48 PM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: listening on multi port in Idudpserver [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 21, 2017 4:11 PM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:

the server code is fully added which show that i have a list
using virtualstringtree what i dont know is how to inject the
channel number to the audio bufferand read the channel number
in server

Obviously, you will have to extend the format of your data packets to
include it. Right now, you are just dumping the raw audio data as-is
by itself with no additional info. So add a header record in front of
the audio data to carry additional metadata about the audio, like its
channel.

--
Remy Lebeau (TeamB)
madammar ellias

Posts: 111
Registered: 8/17/17
Re: listening on multi port in Idudpserver [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 22, 2017 12:29 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Obviously, you will have to extend the format of your data packets to
include it. Right now, you are just dumping the raw audio data as-is
by itself with no additional info. So add a header record in front of
the audio data to carry additional metadata about the audio, like its
channel.

--
Remy Lebeau (TeamB)

i get the idea but the difficult is in coding should i do something like this

udpreciver.SendBuffer(ipaddr, port, RawToBytes('here i dont know how to merege the channeltext in coding to extract it in server'Buffer^, Buffersize));
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: listening on multi port in Idudpserver [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 22, 2017 11:52 AM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:

i get the idea but the difficult is in coding should i do something
like this

<sigh>

Declare a record type containing the extra data you need.

Allocate a TIdBytes whose total length is the byte size of the record
data + the size of the audio bytes.

Copy the record data into the TIdBytes using Move(),
CopyTIdByteArray(), or whatever other serialization you want.

Copy the audio bytes into the TIdBytes following the record data.

Send the TIdBytes.

Reverse the process on the receiver end. Copy out the record data from
the provided TIdBytes as needed, and then copy out the audio data
following the record data.

--
Remy Lebeau (TeamB)
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: listening on multi port in Idudpserver [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 22, 2017 1:38 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Am 22.12.2017 um 20:52 schrieb Remy Lebeau (TeamB):
madammar ellias wrote:

i get the idea but the difficult is in coding should i do something
like this

<sigh>

Declare a record type containing the extra data you need.

Allocate a TIdBytes whose total length is the byte size of the record
data + the size of the audio bytes.

Copy the record data into the TIdBytes using Move(),
CopyTIdByteArray(), or whatever other serialization you want.

Copy the audio bytes into the TIdBytes following the record data.

Send the TIdBytes.

Reverse the process on the receiver end. Copy out the record data from
the provided TIdBytes as needed, and then copy out the audio data
following the record data.

Remy sounds to be right, but it might be wise to declare the record as
being "packed", which means all fields of it start at the next addres
instead of the compiler leaving a few bytes free now and then to
optimize for access performance. The thing is, when the compiler does
this you cannot be sure that it doesn't change in a later version etc.
and one side then gets incompatible with the other side.

Greetings

Markus
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 21, 2017 10:08 AM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:

i can understand the part of adding more binding something like

Binding := udpserver.Bindings.Add;
Binding.IP := '0.0.0.0';
Binding.Port := more ports;

That is not what I said. Read my previous command again more
carefully. You need a separate Bindings entry to each port, eg:

Binding := udpserver.Bindings.Add;
Binding.IP := '0.0.0.0';
Binding.Port := Port1;
 
Binding := udpserver.Bindings.Add;
Binding.IP := '0.0.0.0';
Binding.Port := Port2;
 
Binding := udpserver.Bindings.Add;
Binding.IP := '0.0.0.0';
Binding.Port := Port3;


And so on...

but is the udpserver will communicate only with specific port

TIdUDPServer runs a separate reading thread for each Port that it is
bound to. The OnUDPRead event is fired by each of those threads, where
the event provides the actual Binding object that receives a packet.

or i have to define it in the onread ?

I don't understand what you are asking.

also should i need to restart the server each time adding new port ?

Yes.

--
Remy Lebeau (TeamB)
madammar ellias

Posts: 111
Registered: 8/17/17
Re: listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 24, 2017 2:52 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
<sigh>

Declare a record type containing the extra data you need.

Allocate a TIdBytes whose total length is the byte size of the record
data + the size of the audio bytes.

Copy the record data into the TIdBytes using Move(),
CopyTIdByteArray(), or whatever other serialization you want.

Copy the audio bytes into the TIdBytes following the record data.

Send the TIdBytes.

Reverse the process on the receiver end. Copy out the record data from
the provided TIdBytes as needed, and then copy out the audio data
following the record data.

--
Remy Lebeau (TeamB)

i am trying to do that in coding here where i come i have created packed record like this

type
  THeader = packed record
    Channelname: string;
    Channelnumber: integer;
  end;


then things get more complex in my head

i have started to asign the header and added new variable as tidbytes like this
var
  Header: THeader;
  BufferChannel: TIdBytes;
  PB: PByte;
 Target, Source: PByte;
 Count, Size: Integer;
begin
// fill the channel record as suggested to make a packed record 
  Header.Channelname := 'Channel1';
  Header.Channelnumber  := 5400;
// here start more complex in my head , i have added the rawtobytes audio data to a Tidbytes Variable
 
BufferChannel:= RawToBytes('Buffer^, Buffersize);
//getting the size of hheader
Size := SizeOf(Header);
SetLength(BufferChannel, Size);
 
// at this point i am not sure if all what i have tried is correct then stopped at sending 
 
PB := PByte(BufferChannel);
 
// then i have start to move that header to front of the audio data 
 
 Target := PB;
 source := @Header;
 count := SizeOf(Header);
 move(source, Target, count); // i have got a nil pointer error after executing here
 
end;


i think i am doing it very wrong now
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 25, 2017 1:12 AM   in response to: madammar ellias in response to: madammar ellias
Hello,

if your record contains a string (= a variably sized field), you should
transmit a size field for the whole record.

type
  THeader = packed record
    HeaderSize : UIn16;
    Channelname: string;
    Channelnumber: Integer;
  end;
 
var
  Header : THeader;
 
and before sending of course:
 
  Header.HeaderSize := SizeOf(Header);


On the reading side you need to adapt as well.
=> suggestion: do NOT use a string for the channel name, use a fixed
length array of char, it might make things considerably easier for you.

Greetings

Markus

Am 24.12.2017 um 11:52 schrieb madammar ellias:
Remy Lebeau (TeamB) wrote:
<sigh>

Declare a record type containing the extra data you need.

Allocate a TIdBytes whose total length is the byte size of the record
data + the size of the audio bytes.

Copy the record data into the TIdBytes using Move(),
CopyTIdByteArray(), or whatever other serialization you want.

Copy the audio bytes into the TIdBytes following the record data.

Send the TIdBytes.

Reverse the process on the receiver end. Copy out the record data from
the provided TIdBytes as needed, and then copy out the audio data
following the record data.

--
Remy Lebeau (TeamB)

i am trying to do that in coding here where i come i have created packed record like this

type
  THeader = packed record
    Channelname: string;
    Channelnumber: integer;
  end;


then things get more complex in my head

i have started to asign the header and added new variable as tidbytes like this
var
  Header: THeader;
  BufferChannel: TIdBytes;
  PB: PByte;
 Target, Source: PByte;
 Count, Size: Integer;
begin
// fill the channel record as suggested to make a packed record 
  Header.Channelname := 'Channel1';
  Header.Channelnumber  := 5400;
// here start more complex in my head , i have added the rawtobytes audio data to a Tidbytes Variable
 
BufferChannel:= RawToBytes('Buffer^, Buffersize);
//getting the size of hheader
Size := SizeOf(Header);
SetLength(BufferChannel, Size);
 
// at this point i am not sure if all what i have tried is correct then stopped at sending 
 
PB := PByte(BufferChannel);
 
// then i have start to move that header to front of the audio data 
 
 Target := PB;
 source := @Header;
 count := SizeOf(Header);
 move(source, Target, count); // i have got a nil pointer error after executing here
 
end;


i think i am doing it very wrong now
madammar ellias

Posts: 111
Registered: 8/17/17
Re: listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 26, 2017 4:22 AM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:
Hello,

if your record contains a string (= a variably sized field), you should
transmit a size field for the whole record.

type
  THeader = packed record
    HeaderSize : UIn16;
    Channelname: string;
    Channelnumber: Integer;
  end;
 
var
  Header : THeader;
 
and before sending of course:
 
  Header.HeaderSize := SizeOf(Header);


On the reading side you need to adapt as well.
=> suggestion: do NOT use a string for the channel name, use a fixed
length array of char, it might make things considerably easier for you.

Greetings

Markus

i am still getting a nil pointer in move function then i have changed the sending type like this but on server side how exactly cut this record from the audio ?


if (udpreciver.Active) then
begin
 
Header.Channelname := 'Channel1';
Header.Channelnumber  := 5400;
 
BufferChannel := RawToBytes(Buffer^, Buffersize);
 
 
SetLength(sndbuffer, Length(BufferChannel) + Length(header.Channelname) + SizeOf(header.Channelnumber));
Move(BufferChannel[0], sndbuffer[0], Length(sndbuffer));
 
udpreciver.SendBuffer(ipaddr, portnum, sndbuffer);
end;
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 26, 2017 10:00 AM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:

if your record contains a string (= a variably sized field), you
should transmit a size field for the whole record.

That will not solve the issue. You would still be sending a pointer to
the string data, instead of sending the actual string data.

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 26, 2017 9:58 AM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:

i am trying to do that in coding here where i come i have created
packed record like this

type
  THeader = packed record
    Channelname: string;
    Channelnumber: integer;
  end;

'string' is a dynamically allocated data type. It is just a pointer to
character data that is located elsewhere in memory. As such, you can't
use it (or any other dynamic type) in a record that is used directly in
serialization data. You would end up sending the pointer itself instead
of the data being pointed at.

You need to serialize your data to a flat format, send it, and then
deserialize it on the other end. For instance, sending a string's
length as a fixed Int32 followed by its actual string characters.

If your string data never exceeds 255 bytes, consider using a
ShortString instead, which can be embedded directly into a record:

type
  THeader = packed record
    Channelname: ShortString;
    Channelnumber: Int32;
end;


ShortString has no pointer. Think of it like a fixed array of 256
bytes, where the 1st byte is the length.

Otherwise, you have to serialize the data manually, eg:

type
  TChannelInfo = record
    ChannelName: string;
    ChannelNumber: Int32;
  end;
 
procedure SendIt(const Channel: TChannelInfo; AudioData: TMemoryStream);
var
  Buffer: TIdBytes;
  Count, AudioSize: UInt32;
  Index: Integer;
begin
  Count := IndyTextEncoding_UTF8.GetByteCount(Header.ChannelName);
  AudioSize := AudioData.Size;
 
  SetLength(Buffer, 4 + Count + 4 + 4 + AudioSize);
  Index := 0;
 
  PUInt32(@Buffer[Index])^ := GStack.HostToNetwork(Count);
  Inc(Index, SizeOf(UInt32));
 
  IndyTextEncoding_UTF8.GetBytes(Header.ChannelName, 1,
Length(Header.ChannelName), Buffer, Index);
  Inc(Index, Count);
 
  PUInt32(@Buffer[Index])^ :=
GStack.HostToNetwork(PUInt32(@Channel.ChannelNumber)^);
  Inc(Index, SizeOf(UInt32));
 
  PUInt32(@Buffer[Index])^ := GStack.HostToNetwork(AudioSize);
  Inc(Index, SizeOf(UInt32));
 
  Move(AudioData.Memory^, Buffer[Index], AudioSize);
 
  // send Buffer ...
end;
 
procedure ReadIt(var Channel: TChannelInfo: AudioData: TMemoryStream);
begin
var
  Buffer: TIdBytes;
  Count, AudioSize: UInt32;
  Index: Integer;
begin
  // read Buffer ...
  Index := 0;
 
  Count := GStack.NetworkToHost(PUInt32(@Buffer[Index])^);
  Inc(Index, SizeOf(UInt32));
 
  Header.ChannelName := IndyTextEncoding_UTF8.GetString(Buffer, Index,
Count);
  Inc(Index, Count);
 
  PUInt32(@Channel.ChannelNumber)^ :=
GStack.HostToNetwork(PUInt32(@Buffer[Index])^);
  Inc(Index, SizeOf(UInt32));
 
  AudioSize := GStack.NetworkToHost(PUInt32(@Buffer[Index])^);
  Inc(Index, SizeOf(UInt32));
 
  AudioData.WriteBuffer(Buffer[Index], AudioSize);
end;


--
Remy Lebeau (TeamB)
madammar ellias

Posts: 111
Registered: 8/17/17
Re: listening on multi port in Idudpserver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 27, 2017 1:42 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
madammar ellias wrote:

'string' is a dynamically allocated data type. It is just a pointer to
character data that is located elsewhere in memory. As such, you can't
use it (or any other dynamic type) in a record that is used directly in
serialization data. You would end up sending the pointer itself instead
of the data being pointed at.

You need to serialize your data to a flat format, send it, and then
deserialize it on the other end. For instance, sending a string's
length as a fixed Int32 followed by its actual string characters.

If your string data never exceeds 255 bytes, consider using a
ShortString instead, which can be embedded directly into a record:

type
  THeader = packed record
    Channelname: ShortString;
    Channelnumber: Int32;
end;


ShortString has no pointer. Think of it like a fixed array of 256
bytes, where the 1st byte is the length.

Otherwise, you have to serialize the data manually, eg:

type
  TChannelInfo = record
    ChannelName: string;
    ChannelNumber: Int32;
  end;
 
procedure SendIt(const Channel: TChannelInfo; AudioData: TMemoryStream);
var
  Buffer: TIdBytes;
  Count, AudioSize: UInt32;
  Index: Integer;
begin
  Count := IndyTextEncoding_UTF8.GetByteCount(Header.ChannelName);
  AudioSize := AudioData.Size;
 
  SetLength(Buffer, 4 + Count + 4 + 4 + AudioSize);
  Index := 0;
 
  PUInt32(@Buffer[Index])^ := GStack.HostToNetwork(Count);
  Inc(Index, SizeOf(UInt32));
 
  IndyTextEncoding_UTF8.GetBytes(Header.ChannelName, 1,
Length(Header.ChannelName), Buffer, Index);
  Inc(Index, Count);
 
  PUInt32(@Buffer[Index])^ :=
GStack.HostToNetwork(PUInt32(@Channel.ChannelNumber)^);
  Inc(Index, SizeOf(UInt32));
 
  PUInt32(@Buffer[Index])^ := GStack.HostToNetwork(AudioSize);
  Inc(Index, SizeOf(UInt32));
 
  Move(AudioData.Memory^, Buffer[Index], AudioSize);
 
  // send Buffer ...
end;
 
procedure ReadIt(var Channel: TChannelInfo: AudioData: TMemoryStream);
begin
var
  Buffer: TIdBytes;
  Count, AudioSize: UInt32;
  Index: Integer;
begin
  // read Buffer ...
  Index := 0;
 
  Count := GStack.NetworkToHost(PUInt32(@Buffer[Index])^);
  Inc(Index, SizeOf(UInt32));
 
  Header.ChannelName := IndyTextEncoding_UTF8.GetString(Buffer, Index,
Count);
  Inc(Index, Count);
 
  PUInt32(@Channel.ChannelNumber)^ :=
GStack.HostToNetwork(PUInt32(@Buffer[Index])^);
  Inc(Index, SizeOf(UInt32));
 
  AudioSize := GStack.NetworkToHost(PUInt32(@Buffer[Index])^);
  Inc(Index, SizeOf(UInt32));
 
  AudioData.WriteBuffer(Buffer[Index], AudioSize);
end;


--
Remy Lebeau (TeamB)

should i have to use memorystream to send ? why not using tidbytes directly ?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: listening on multi port in Idudpserver
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 4, 2018 12:56 PM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:

should i have to use memorystream to send ?

Indy's UDP components do not support sending/reading streams.

why not using tidbytes directly ?

You HAVE to use TIdBytes with Indy's UDP components. The example I
showed does exactly that.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02