I made an NSStream socket to connect to the telnet server. In fact, it can perfectly connect to the server; I received an inputStream with the "first word" of the server, but I do not understand this. I am looking for some explanation of telnet IAC commands.
Here is my code to get 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 EventHasBytesAvailable. It works fine (received greetings from the server with a login prompt).
Now, to send 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 wrote a script on the button to find out what happens when I use the output stream: EventHasBytesAvailable to catch my output has an input ... The server tells me what I told him!
Can someone explain to me the IAC commands and / or how to go to the login on the server and send the commands?
Cindy broutin
source share