-
-
Notifications
You must be signed in to change notification settings - Fork 4
SSH.TCPListener
SSH.TCPListener
Protected Class TCPListener
This class instructs the SSH server to begin listening for inbound TCP connections on the RemoteInterface and RemotePort. If RemoteInterface
is the empty string then the server will listen on all of its interfaces. If RemotePort
is zero then the server will select a random ephemeral port which you can determine by reading the RemotePort
property after StartListening()
returns successfully.
While listening, newly established TCP connections will be passed to the ConnectionReceived()
event.
Calling the StopListening()
method will discontinue listening for new connections but will not disturb connections that are already established.
This example is a console application that accepts connections forwarded from the server and echoes back anything sent over the connection:
Class App
Inherits ConsoleApplication
Event Function Run(args() As String) As Integer
Dim session As SSH.Session = SSH.Connect("ssh.example.com", 22, "username", "password")
Dim listener As New SSH.TCPListener(session)
AddHandler listener.ConnectionReceived, WeakAddressOf ConnectionReceivedHandler
listener.RemotePort = 80 ' the port that the SSH server should listen on
listener.RemoteInterface = "127.0.0.1" ' the network interface that the SSH server should listen on
listener.StartListening()
Do Until Not listener.IsListening
' we must periodically Poll the listener for activity
' Poll() will automatically call StopListening() if an error occurs.
listener.Poll()
Loop
End Function
Private Sub ConnectionReceivedHandler(Sender As SSH.TCPListener, Connection As SSH.TCPTunnel)
#pragma Unused Sender
' For this example, simply echo back whatever is sent over the connection
Dim data As String = Connection.Read(Connection.BytesReadable)
Connection.Write(data)
Connection.Close
End Sub
End Class
- Handle As Ptr
- IsListening As Boolean
- LastError As Int32
- MaxConnections As Integer
- RemoteInterface As String
- RemotePort As Integer
- Session As SSH.Session
- TCPTunnel class
Wiki home | Project page | Bugs | Become a sponsor
Text and code examples are Copyright ©2018-24 Andrew Lambert, offered under the CC BY-SA 3.0 License.