I try to connect telnet to my telnet server port 23 in iOS.
I use the "cocoaAsyncSocket" library.
I can received the data from the telnet.
But I try to decode to the string , the data is not my expect.
It will show
(null)
If I use NSASCIIStringEncodeing to decode.
It will show
ÿýÿý ÿý#ÿý'
I use the terminal command, telnet myIP 23.
I can get below in terminal.
james$ telnet 192.168.2.94 23
Trying 192.168.2.94...
Conn ected to txxxxx.xxxxx.com.
Escape character is '^]'.
Password:
how can I parse to the "Password:" string in iOS?
thank you .
my connect code below:
- (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");
}