Cocoa - XTelnet ClientX -> SSH client

Discussion in 'Mac Programming' started by DennisBlah, Aug 12, 2015.

  1. DennisBlah, Aug 12, 2015
    Last edited: Aug 12, 2015

    DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #1
    Hi all,

    I recently created an telnet client for iOS.
    With a few minor changes I made it for OSX.

    However, I'm receiving this kind of replies:
    ÿûÿþ"ÿþÿýÿýÿýÿûÿþ"ÿþÿýÿýÿý

    Instead of normal text.

    how do I find out what encoding I need to use?
    (Running freesshd on a windows server)

    Using the following:
    Code:
    while ([inputStream hasBytesAvailable]) {
      streamOutput = nil;
      len = [inputStream read:buffer maxLength:sizeof(buffer)];
      if (len > 0) {
        for(int a=1; a<30; a++) {
          NSString * serverSaid = [[NSString alloc] initWithBytes:buffer length:len encoding: a];
          NSLog(@"Server: %@", serverSaid);
        }
      }
    }
    
    I only receive stuff like:
    Code:
    2015-08-12 12:35:40.265 TerminalX[5997:348189] Server: ÿûÿþ"ÿþ
    2015-08-12 12:35:40.265 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.271 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.271 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.271 TerminalX[5997:348189] Server: ÿûÿþ"ÿþ
    2015-08-12 12:35:40.276 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.276 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.276 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.281 TerminalX[5997:348189] Server: ˙ű˙ţ"˙ţ
    2015-08-12 12:35:40.281 TerminalX[5997:348189] Server: ǿ︢￾ÿﴃ�᣿ﴟ
    2015-08-12 12:35:40.286 TerminalX[5997:348189] Server: яыяю"яю
    2015-08-12 12:35:40.287 TerminalX[5997:348189] Server: ÿûÿþ"ÿþ
    2015-08-12 12:35:40.291 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.296 TerminalX[5997:348189] Server: ÿûÿş"ÿş
    2015-08-12 12:35:40.296 TerminalX[5997:348189] Server: ˙ű˙ţ"˙ţ
    2015-08-12 12:35:40.297 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.297 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.297 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.297 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.297 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.297 TerminalX[5997:348189] Server: ÿûÿþ"ÿþ
    2015-08-12 12:35:40.297 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.297 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.297 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.297 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.297 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.297 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.297 TerminalX[5997:348189] Server: (null)
    2015-08-12 12:35:40.297 TerminalX[5997:348189] Server: (null)
    
     
  2. cqexbesd macrumors regular

    Joined:
    Jun 4, 2009
    #2
    There is RFC2066 but I don't know how widely implemented it is and if it was ever ratified. I don't expect there to be many updates to telnet any time soon... Your only other option is to ask the user with a default of something sensible - normally that would be UTF-8 but if you are talking to things that still us telnet maybe its ASCII.

    Are you sure you are only having encoding problems though? I would try a) doing a packet capture and see what is actually being sent and received and b) try a different telnet server and see if the behaviour is any different.
     
  3. DennisBlah, Aug 12, 2015
    Last edited: Aug 13, 2015

    DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #3
    Thanks cqexbesd, I think that there is something with the freesshd server indeed.
    I now installed bitvise ssh server, but this will need ssh client.
    From terminal, ofcourse its no problem.

    Doing some small research and I got libssh2 to compile and include in my project.
    Together with some small examples I got it to work, however I now seem to struggle with ANSI code.
    How can I use ANSI in a NSTextView?
    I mean.. how do I parse this?
     
  4. cqexbesd macrumors regular

    Joined:
    Jun 4, 2009
    #4
    I don't know but I would be surprised if NSTextView had any ANSI support built in. Maybe someone has already written something and released it open source but I suspect you will have to parse the character stream and map escape sequences to the appropriate API calls yourself.
     
  5. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #5
    Since this was a Windows machine, chances are that it's either MS specific extended ascii or UTF16. Since all characters are messed up however, I world guess on UTF16, because even with extended ascii you world get sensible text out of the ascii range. The "beauty" of UTF16 is that there are three encodings available, little and big endian, plus a bastard fixed size MS specific version. Perhaps you can check on the Windows machine or just by trial and error on your end.
     
  6. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #6
    I don't recall the details, but way back in the day of using VT terminals and emulators I recall seeing such odd characters when the terminal was not setup quite right to the server. Can't remember if it was 8 bit versus 7 bit coding or something else. I'd look up a manual for a VT terminal an do a little digging on syncing of settings.
     
  7. cqexbesd macrumors regular

    Joined:
    Jun 4, 2009
    #7
    BTW you don't say if you have already dealt with option negotiation...not sure what happens if you just assume everything sent is text. Probably not the issue though.
     
  8. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #8
    I think this thread has turned into the following one, by the same user:
    http://forums.macrumors.com/threads/cocoa-nstextview-and-terminal-escape-sequences.1907661/

    The linked thread provides some additional detail. It also seems that the "many kinds of accented y's, with occasional thorns" has become a different beast.
     

Share This Page