C# streamreader wtf

Discussion in 'Software' started by mastermosley, May 13, 2011.

  1. mastermosley

    mastermosley Sergeant

    Just messing around and made a simple telnet server, you connect, the server sends a message to the client via streamwriter a welcome and then sits and waits for the client to send a message back. All messages sent from the client are simply relayed back to the client with a "SERVER: MessageSend". On the first message relayed back i get a bunch of weird symbols: ���� ����'������ (thats what it looks like in the telnet client). The code prior to this is:

    writer.Write("Message: ");
    writer.Flush();

    and then when the client sends a message
    line = reader.ReadLine();

    I dont think this will be a problem, I can simply make a regex and get rid of all non ansci characters but any idea why I am getting this?
     
  2. mastermosley

    mastermosley Sergeant

    Got another question. I use writer.WriteLine("Password: "); how would I make it so when the user types the next characters into the telnet client they are password chars or invisible?
     
  3. mastermosley

    mastermosley Sergeant

    I haven't figured out where the random bytes were coming from, but I just used a regex to get rid of all alpha-numeric characters seeing how those are the only characters I will be dealing with.
    Code:
    line = Regex.Replace(line, @"[\W]", "");
    
    As for my second question, I wasn't thinking clearly at the time, the answer was simple, just had to use an ansci color code and made it invisible,

    ESC[8;

    Cheers
     
  4. mastermosley

    mastermosley Sergeant

    Finally figured out what the random bytes are, and I should have known. They are simply the telnet negotiation code sent from the telnet client. And they should be properly handled. If anyone else runs into this, this RFC helped.

    http://tools.ietf.org/html/rfc855
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds