0

I have created a UDP client and it works great. The data is coming back in the correct format (verified through wireshark). The problem is the format I receive from streamreader is not what I expected.

Here is the code

private async void OnMessageReceived(DatagramSocket sender,     
 DatagramSocketMessageReceivedEventArgs args)
    {
        Debug.WriteLine("message recv");
        var result = args.GetDataStream();

        var resultStream = result.AsStreamForRead(1024);
        using (var reader = new StreamReader(resultStream))
        {
            string text = await reader.ReadToEndAsync();
            Debug.WriteLine(text);
        }
    }

Here is the wireshark data

00 00 ff ff

Here is the text that is generated when I run my code

"?\0\u0002\0?\0\0d\0\0\u0001\u0001\0\0??"

I am assuming its a formatting issue.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
user3363744
  • 167
  • 1
  • 9
  • Very unclear what you expect to get out of `00 00 ff ff` bytes as a string. Consider providing [MCVE] - inline data you receive as byte array and also show expected output along with what you get. – Alexei Levenkov Jul 26 '16 at 03:40
  • From your expected result it looks like your data is binary stream. Why StreamReader? – bansi Jul 26 '16 at 03:47
  • i want to see 00 00 ff ff as a string. Thats my data – user3363744 Jul 26 '16 at 04:01
  • if not Streamreader, what should i use? – user3363744 Jul 26 '16 at 04:03
  • @user3363744: As a string... using what encoding? UTF-8, UTF-16, UTF-32 would all interpret those 4 bytes differently (and there are many other encodings for string data). – Eric J. Jul 26 '16 at 04:39

1 Answers1

0

Have a look at this post: Extract Server Name Indication (SNI) from TLS client hello

In particular:

  • The host is utf8 encoded and readable when you utf8 enocde the buffer.
  • Theres one byte before the host, that determines it's length.
Community
  • 1
  • 1
Moustachio
  • 184
  • 2
  • 23