1

I created an Asynchronous SslStream Listener but it did not receive the message from the client properly

The Listener Code

Code Removed

joran i don't want the code to be here anymore

Here is the message i try to send to the server "Hello From Client"

and here is how my server console show it

Hello
 From
 Clie
t 

Can someone tell me why i did not receive the message correctly ?, it is really very weird and i can't solve it please i want help

And\Or can i use StreamReader to receive a message ? is it non blocking so the code will remain asynchronous ?

Daniel Eugen
  • 2,712
  • 8
  • 33
  • 56

1 Answers1

0

You haven't posted the code where you convert the generated byte array to a string, which would help. Seeing as you're declaring your read buffer as 5 bytes in length I suspect this has something to do with the 5 characters per line output.

pixelbadger
  • 1,556
  • 9
  • 24
  • it is the first buffer only which i set to 5 but after i set size = sslstream.EndRead, so it must read the right message length of the message comes after the first receive – Daniel Eugen Sep 13 '12 at 22:08
  • Also my code to convert the bytes is simply Encoding.ASCII.GetString(e.Buffer); – Daniel Eugen Sep 13 '12 at 22:08
  • When i print the sizes returned from EndRead i found them to be all 5,5,5,5,5,5 – Daniel Eugen Sep 13 '12 at 22:09
  • After Analyzing it many time i think it determines the length to 5 because the first message length the socket receives is 5 idk it is very weird so please help i am very confused – Daniel Eugen Sep 13 '12 at 22:20
  • Yes, but SslStream.EndRead returns the number of bytes read, which is 5 in the first instance. As you use this value in your subsequent calls to Create buffer the size will always be 5. Something is inserting carriage returns between each of these 5 characters. – pixelbadger Sep 13 '12 at 22:23
  • so what i should do to fix that this problem is driving me crazyyy – Daniel Eugen Sep 13 '12 at 22:26
  • i tried to change the buffer this in the EndAuthenticate from 5 to any other value, what happens is the first message is received correctly then all the others are set to 5 too – Daniel Eugen Sep 13 '12 at 22:27
  • Any HELP ? i am still stuck at this point ! – Daniel Eugen Sep 14 '12 at 00:23