Sample code for 30+ languages & platforms
Swift

Check SSH Connection (IsConnected)

Demonstrates how to check to see if the connection to the SSH server exists.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let ssh = CkoSsh()!

    // Connect to an SSH server:
    success = ssh.connect(hostname: "192.168.1.209", port: 22)
    if success != true {
        print("\(ssh.lastErrorText!)")
        return
    }

    // Is the last known state "connected"?
    var connected: Bool = ssh.isConnected
    if connected == true {
        // Verify for sure by sending an ignore message.
        connected = ssh.sendIgnore()
    }

    print("connected = \(connected)")

    // Disconnect.
    ssh.disconnect()

    // Am I still connected?
    connected = ssh.isConnected
    print("connected = \(connected)")

}