Skip to content

SSH.TCPListener

Andrew Lambert edited this page Nov 12, 2020 · 14 revisions

SSH.TCPListener

Class Declaration

 Protected Class TCPListener

Remarks

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 port which you can determine by reading the RemotePort after StartListening finishes successfully.

Example

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 = "192.168.1.5" ' 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 Sub

 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 = Stream.Read(Connection.BytesReadable)
  Connection.Write(data)
  Connection.Close
End Sub

End Class

Event definitions

Methods

Properties

See also

Clone this wiki locally