Remote Streamlocal Forwarding
Create an OpenSSH streamlocal listener on the SSH server side and accept raw incoming Unix-socket channels.
SSHConnection.withRemoteStreamLocalForwardListener(...) creates a Unix domain socket listener on the SSH server side. Remote processes connect to that socket path, and Traversio yields each incoming connection as a raw SSHForwardedStreamLocalChannel.
Use it when:
- the remote side needs a Unix socket path as the entry point
- your Swift code wants to handle each accepted connection directly
- you need OpenSSH
[email protected]rather than a TCP remote port
Mental Model
remote process
-> remote Unix socket path
-> SSH [email protected] channel
-> your Swift codeThe API is closure-scoped. Traversio requests the remote listener before the body runs, cancels the listener when the body exits, and cancels pending accepts during shutdown.
Example
import Traversio
func serveRemoteSocket(configuration: SSHClientConfiguration) async throws {
try await SSHClient.withConnection(configuration: configuration) { connection in
try await connection.withRemoteStreamLocalForwardListener(
socketPath: "/tmp/traversio.sock"
) { listener in
let channel = try await listener.accept()
var request: [UInt8] = []
while let event = try await channel.nextEvent() {
switch event {
case let .data(bytes):
request += bytes
case .endOfFile:
try await channel.write("received \(request.count) bytes\n")
try await channel.sendEOF()
return
}
}
}
}
}What You Get Back
SSHRemoteStreamLocalForwardListener exposes:
socketPathaccept()
SSHForwardedStreamLocalChannel exposes:
socketPathwrite(_:)write(_ string: String)sendEOF()close()readChunk()nextEvent()eventscollectDataUntilClose()
Supporting public types:
SSHForwardedStreamLocalChannelOutputSSHStreamLocalChannelEventSSHStreamLocalChannelEventSequence
Support Status
Current state:
- listener setup uses OpenSSH
[email protected] - incoming channels use
[email protected] - shutdown sends
[email protected]and validates the empty success response - live validation covers an OpenSSH target by connecting a remote Python Unix-socket client to the server-side socket path
The listener shares the same managed-channel receive-window, EOF, close, and cancellation-aware event-stream behavior as the raw TCP forwarding wrappers.