ios telnet

Apple and swift is new to me.

I am trying to make an ios app that can talk with an telnet server.

Any idea of where to find information about this topic (using telnet in swift)?

Pleas explain whether you actually want a TCP/IP connection, a TCP/IP connection using streams, a TCP/IP connection implementing RFC 854, a TCP/IP connection implementing RFC 137, or something else.

IOS app should connect to a telnet server via simple TPC/IP.

What type of RFC it actually uses i do not know, but.

Via hyperterminal in windows i can connect with ANSI emulation, so as far as i know it is the simplest form of socket communication.

I have made connections via pc and .Net in the past, in short it worked like so:

Pc: TcpIp connect to telnet server (ip, subnet, gateway)

Server reply: :>Login

Pc: Admin

Server reply: :>Connected

Now pc and telnet server is connected and commands can be send to telnet server and it will reply.

As far as i know it is not nessesary to implement any RFC.

(Telnet server and iphone will be connected to the save wifi router).

There are three components to your typical telnet setup:

  • the basic TCP connection which carries the data (A)

  • a mechanism for inserting telnet control information into that TCP connection (B)

  • terminal emulation (C)

iOS has a variety of APIs for A. I generally point folks towards NSStream. For example, you can create a pair of streams that represent a TCP connection to the telnet server on a

example.com
with this code:
NSInputStream *    inStream;
NSOutputStream *    outStream;

[NSStream getStreamsToHostWithName:@"example.com"
    port:23
    inputStream:&inStream
    outputStream:&outStream
];

There’s a bunch of NSStream documentation and sample code on the developer web site. A good place to start might be RemoteCurrency, which shows how to implement line buffering on an NSStream connection.

iOS has no direct support for B or C. If you need these, you’ll have to either write or acquire the code for doing them.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Im sure that (B) and (C) is no problem, so I will focus no testing NSStream (thanks Eskimo).

Programming is not new to me (at all), but this is my first try at Apple's swift.

So Points on how i can test NSStream?, maybe an NSStream for dummy's 😁.

Starting programming swift was easy, many toturials - this is sadly not the case for using NSStream.

Yes i can find plenty of objective-c examples, but none using swift.

The "RemoteCurrency" contains no swift code or am i missing somthing?.

Yes i can find plenty of objective-c examples, but none using swift.

IMO it’s well worth the effort required to gain a reading knowledge of Objective-C. You don’t really need to follow the details of the code, but you should be able to extract the overall flavour so that you can apply the same approach in Swift.

Having said that, I’ve recently been working on a Swift NSStream sample, so here’s some code extracted from that.

private func hasSpaceAvailable() {
    … implement the write side …
}

private func hasBytesAvailable() {
    var buffer = [UInt8](count: 16, repeatedValue: 0)
    let bytesRead = self.inputStream!.read(&buffer, maxLength: buffer.count)
    if bytesRead > 0 {
        for b in buffer[0..<bytesRead] {
            … process a byte …
        }
    }
}

private func streamDisconnectionOccurred() {
    self.stopConnection()
}

func stream(aStream: NSStream, handleEvent eventCode: NSStreamEvent) {
    switch eventCode {
    case NSStreamEvent.OpenCompleted:
        // do nothing -- We ignore the .OpenCompleted event because a) it's a
        // pain to account for the two streams stream and b) in some cases
        // (like when you have TLS enabled) the stream isn't really up until
        // .HasBytesAvailable arrives.
        break
    case NSStreamEvent.HasBytesAvailable:
        self.hasBytesAvailable()
    case NSStreamEvent.HasSpaceAvailable:
        self.hasSpaceAvailable()
    case NSStreamEvent.ErrorOccurred:
        self.streamDisconnectionOccurred()
    case NSStreamEvent.EndEncountered:
        self.streamDisconnectionOccurred()
    default:
        fatalError()
    }
}

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
ios telnet
 
 
Q