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?