0

我尝试在 iOS 中将 telnet 连接到我的 telnet 服务器端口 23。

我使用“ cocoaAsyncSocket ”库。

我可以从 telnet 接收数据。

但我尝试解码为字符串,数据不是我的预期。

它会显示

 (null)

如果我使用 NSASCIIStringEncodinging 来解码。

它会显示

 ÿýÿý ÿý#ÿý'

我使用终端命令 telnet myIP 23。

我可以在终端下面。

  james$ telnet 192.168.2.94 23
 Trying 192.168.2.94...
 Conn ected to txxxxx.xxxxx.com.
 Escape character is '^]'.
 Password: 

如何解析到 iOS 中的“密码:”字符串?

谢谢你 。

我的连接代码如下:

 - (void)viewDidLoad {
     [super viewDidLoad];
     asyncSocket = [[GCDAsyncSocket alloc] initWithDelegate:self    delegateQueue:dispatch_get_main_queue()];

     buffer = [[NSMutableData alloc] init];
      [asyncSocket connectToHost:@"192.168.2.94" onPort:23 error:nil];
 }

 - (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port{
     NSLog(@"did connect to host");
      [asyncSocket readDataWithTimeout:-1 tag:0];
 }

 - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag {
          NSLog(@"didReadData(%lu): %@", tag, @([data length]));
          [buffer setLength:0];

      NSString* message = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
 //            NSString* message = [[NSString alloc] initWithData:data  encoding:NSUTF8StringEncoding];
     NSLog(@"message is: \n%@",message);



     [asyncSocket readDataWithTimeout:-1 buffer:buffer bufferOffset:[buffer length] tag:tag];
 }

 - (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err
 {
   NSLog(@"socket disconnect to host");

 }
4

0 回答 0