Poco::WebTunnel

class LocalPortForwarder

File Information

Library: WebTunnel
Package: WebTunnel
Header: Poco/WebTunnel/LocalPortForwarder.h

Description

This class forwards a local port to a remote host, using a WebSocket tunnel connection.

Member Summary

Member Functions: forward, getLocalTimeout, getRemoteTimeout, localPort, remotePort, remoteURI, setLocalTimeout, setRemoteTimeout

Constructors

LocalPortForwarder

LocalPortForwarder(
    Poco::UInt16 localPort,
    Poco::UInt16 remotePort,
    const Poco::URI & remoteURI,
    WebSocketFactory::Ptr pWebSocketFactory
);

Creates a LocalPortForwarder, using the given localPort to forward to the given remotePort on the remote system, using a WebSocket connected to remoteURI.

If localPort is 0, an ephemeral port number is used. This is recommended, as it avoids conflicts with already used port numbers. The localPort() member function can be used to obtain the actual port number.

The forwarding socket is always bound to the localhost interface for security reasons.

LocalPortForwarder

LocalPortForwarder(
    const Poco::Net::SocketAddress & localAddress,
    Poco::UInt16 remotePort,
    const Poco::URI & remoteURI,
    Poco::Net::TCPServerParams::Ptr pServerParams,
    WebSocketFactory::Ptr pWebSocketFactory
);

Creates a LocalPortForwarder, using the given local address to forward to the given remotePort on the remote system, using a WebSocket connected to remoteURI.

If the port number given in localAddress is 0, an ephemeral port number is used. This is recommended, as it avoids conflicts with already used port numbers. The localPort() member function can be used to obtain the actual port number.

The forwarding socket is bound to the address given in localAddress, which must have either a wildcard IP address, a loopback IP address, or the IP address of one of the host's network adapters.

The given pServerParams are passed to the Poco::Net::TCPServer handling connections to the local forwarding port.

Destructor

~LocalPortForwarder

~LocalPortForwarder();

Destroys the LocalPortForwarder, closing all open connections.

Member Functions

getLocalTimeout inline

Poco::Timespan getLocalTimeout() const;

Returns the timeout for the local connection.

getRemoteTimeout inline

Poco::Timespan getRemoteTimeout() const;

Returns the timeout for the remote WebSocket connection.

localPort inline

Poco::UInt16 localPort() const;

Returns the local port number.

remotePort inline

Poco::UInt16 remotePort() const;

Returns the remote port number.

remoteURI inline

const Poco::URI & remoteURI() const;

Returns the remote host name.

setLocalTimeout

void setLocalTimeout(
    Poco::Timespan timeout
);

Sets the timeout for the local connection.

setRemoteTimeout

void setRemoteTimeout(
    Poco::Timespan timeout
);

Sets the timeout for the remote WebSocket connection.

forward protected

void forward(
    Poco::Net::StreamSocket & socket
);

Securely control IoT edge devices from anywhere   Connect a Device