J'essaye de créer une application en C# qui lit l'activité du port IAX2 4569. J'ai déjà créé les écouteurs UDP et TCP mais quand j'essaye de convertir le UDP partie de données à une chaîne j'ai trouvé des codes étranges. Je ne sais pas si je le fais bien. Certains aident avec ceci j'ai besoin. Cette classe est l'UDPHeader à partir de laquelle j'obtiens les données.Comment convertir l'en-tête UDP du port IAX2 en chaîne lisible
public class UDPHeader
{
//UDP header fields
private ushort usSourcePort; //Sixteen bits for the source port number
private ushort usDestinationPort; //Sixteen bits for the destination port number
private ushort usLength; //Length of the UDP header
private short sChecksum; //Sixteen bits for the checksum
//(checksum can be negative so taken as short)
//End UDP header fields
private byte[] byUDPData = new byte[4096]; //Data carried by the UDP packet
public UDPHeader(byte [] byBuffer, int nReceived)
{
MemoryStream memoryStream = new MemoryStream(byBuffer, 0, nReceived);
BinaryReader binaryReader = new BinaryReader(memoryStream);
//The first sixteen bits contain the source port
usSourcePort = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
//The next sixteen bits contain the destination port
usDestinationPort = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
//The next sixteen bits contain the length of the UDP packet
usLength = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
//The next sixteen bits contain the checksum
sChecksum = IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
//Copy the data carried by the UDP packet into the data buffer
Array.Copy(byBuffer,
8, //The UDP header is of 8 bytes so we start copying after it
byUDPData,
0,
nReceived - 8);
}}
Ensuite, j'ai une classe pour convertir les données de l'UDPHeader en texte normal. Ce est le constructeur:
public IAXHeader(byte[] byBuffer, int nReceived)
{
MemoryStream memoryStream = new MemoryStream(byBuffer, 0, nReceived);
StringReader stringReader = new StringReader(Encoding.UTF8.GetString(memoryStream.ToArray()));
/** iterate lines of stringReader **/
string aLine = stringReader.ReadLine();
}
Le Console.WriteLine de ALINE est la suivante:
Je dois savoir ce que je fais mal à décoder les octets de données UDP IAX2.
Merci, j'ai lu le protocole et modifié mon code. Les données d'en-tête IAX2 sont cryptées et en binaire. Je travaille toujours sur le cryptage mais j'ai les données dont j'avais besoin. Merci encore. – Lichblitz