You can use handlers going in the other direction, too. If you want to programmatically process forwarded data from a remote host, you can use the @#remote@ method.  This takes two parameters, with an optional third parameter. The two required parameters are the handler to use, and the remote port that should be listened to. The optional parameter is the remote bind address, which defaults to '127.0.0.1'.

(Incidentally, if the port is 0, a new port will be allocated for you automatically by the server.)

Whenever connections are received on the remote port, they will be forwarded to the handler, which may implement the following callbacks:

table(list).
|_. Callback |_. Description |
|=^. @error@ | This is invoked if the forward could not be initiated. It accepts a single parameter, which is the error message. |
|=^. @on_close@ | This is invoked when the channel that was assigned to process this forwarded connection has been closed. The callback takes one parameter: the channel itself. |
|=^. @on_eof@ | This is invoked when the remote end of the connection has promised not to send any more data. The local end of the channel may continue to send data, however. This callback takes on parameter: the channel itself.|
|=^. @on_open@ | This is invoked when a new connection is received over the forwarded channel. It accepts five parameters: the channel object, the connected address, the connected port, the originator address, and the originator port. |
|=^. @on_receive@ | This is invoked when data is received over the channel from the remote connection. It accepts two parameters: the channel object, and the data that was received. |
|=^. @setup@ | This is invoked immediately after the forward request has been acknowledged as successful. It accepts a single parameter, which is the port that was assigned to this forward. If the port parameter to @#remote@ was not 0, then that same value will be passed to the callback. Otherwise, the newly allocated port number will be passed to the callback. |

Note that the @on_receive@ handler is required--all other callbacks may remain unimplemented by the handler.
