1

我已经制作了一个NSStream套接字来连接到远程登录服务器。实际上,它可以很好地连接到服务器;我得到了inputStream服务器的“第一句话”,但我不明白。我正在寻找有关 telnet IAC 命令的一些解释。

这是我从服务器接收的代码:

 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;

它基于 EventHasBytesAvailable。它工作正常(通过登录提示从服务器获得你好)。

现在,要发送到服务器,我这样做:

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

我在一个按钮上编写了输出脚本,看看当我使用输出流时会发生什么: EventHasBytesAvailable 捕获我的输出有输入......服务器告诉我我告诉他的内容!

有人可以向我解释 IAC 命令和/或如何继续登录服务器并发送命令吗?

4

0 回答 0