Telnet IAC commands (NSStream socket)

落爺英雄遲暮 提交于 2020-01-06 02:51:06

问题


I've made a NSStream socket to connect to a telnet server. Actually, it can connect fine to the server; I got an inputStream with the "first words" of the server, but I don't understand it. I'm looking for some explanations about the telnet IAC commands.

Here is my code to receive from the server:

 case NSStreamEventHasBytesAvailable:

            if (theStream == inputStream) {

                uint8_t buffer[1024];
                int len;

                while ([inputStream hasBytesAvailable]) {
                    len = [inputStream read:buffer maxLength:sizeof(buffer)];
                    if (len > 0) {

                        NSString * serverSaid = [[NSString alloc] initWithBytes:buffer length:len encoding:NSASCIIStringEncoding];

                        if (nil != serverSaid) {
                            NSLog(@"The server said: %@", serverSaid);
                            [connectLog insertText:serverSaid];
                            [connectLog insertText:@"\r"];
                        }
                    }
                }
            }

            break;

It is based on the EventHasBytesAvailable. It is working fine (got the hello from server with the login prompt).

Now, to send to the server, I do this:

NSString * theMsg  = [NSString stringWithFormat:@"root"];
NSData * msgToSend = [[NSData alloc] initWithData:[theMsg dataUsingEncoding:NSUTF8StringEncoding]];
[outputStream write:[msgToSend bytes] maxLength:[msgToSend length]];

I scripted the output on a button, to see what happen when I use the outputstream: EventHasBytesAvailable catch my output has input... The server is telling me what I told him!

Can someone explain to me the IAC commands and/or how to to proceed to login on the server and send commands?

来源:https://stackoverflow.com/questions/10392045/telnet-iac-commands-nsstream-socket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!