I have an error when I try to do this. My code is based on eskimo's. My version of it is:
import Foundation
import Network
class SSH_Session: ObservableObject{
public private(set) var listener: NWListener? = nil
public private(set) var ButtonText: String = ""
@Published public private(set) var isListening: Bool = false
init(){
setButtonText( false )
}
public func start(){
print("listener will start")
listener = (try? NWListener(using: .tcp) ) ?? nil
if (listener == nil) {
print( "Failed listener acquisition." )
setButtonText( false )
}else {
listener?.stateUpdateHandler = { newState in
print("listener did change state, new: \(newState)", "" )
if( (self.listener?.debugDescription != nil) && (self.listener?.debugDescription != "") ) {
print( " " + self.listener!.debugDescription )
}else{
print( "\n" )
}
}
listener?.service = .init(type: "_ssh._tcp")
listener?.newConnectionHandler = { connection in
let remotePeer = connection.currentPath?.remoteEndpoint
print("listener rejected a receive connection, from: \(remotePeer as Optional)")
connection.cancel()
}
listener?.start(queue: .main)
setButtonText( true )
}
return
}
public func stop() {
print("listener will stop")
self.listener?.stateUpdateHandler = nil
self.listener?.cancel()
setButtonText( false )
}
public func StartStop() {
if( self.isListening ) {
self.stop()
} else {
self.start()
}
}
private func setButtonText( _ isListening: Bool )
{ self.isListening = isListening
ButtonText = isListening ? "Close SSH Connection" : "Open SSH Connection"
}
}
In my version of stateUpdateHandler I included a verbose diagnostic.
Xcode is installed in the iPhone 14, and it is in developer mode. I turned off Bluetooth, WiFi, and cell service even though it is not connected to a cell service.
Info.plist is not automatically added to a project since Xcode 13. I am using Xcode 14.3. When the project was created I did not know to add one. So I used the properties GUI. In the "Build Settings" tab I added the key value pair shown in this screenshot:
The screenshot includes the error I got. I copy and paste its text here:
listener will start
listener did change state, new: ready
[L1 failed, local endpoint: <NULL>, parameters: tcp, local: ::.49728, definite, attribution: developer, server, port: 49728, path satisfied (Path is satisfied), interface: en0[802.11], ipv4, dns, service: <NULL>._ssh._tcp.<NULL> txtLength:0]
listener did change state, new: failed(-65555: NoAuth)
[L1 failed, local endpoint: <NULL>, parameters: tcp, local: ::.49728, definite, attribution: developer, server, port: 49728, path satisfied (Path is satisfied), interface: en0[802.11], ipv4, dns, service: <NULL>._ssh._tcp.<NULL> txtLength:0]
The terminal program in the MacStudio does not show any SSH servers are available iPhone. The iPhone's SSH service appears not to be advertised.
I do not know what to do about this error. Any suggestions would be appreciated.