Poco::WebTunnel

class RemotePortForwarder

File Information

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

Description

This class forwards one or more ports to a remote host, using a shared web socket for tunneling the data.

Member Summary

Member Functions: closeWebSocket, demultiplex, demultiplexError, demultiplexTimeout, forwardData, getConnectTimeout, getLocalTimeout, multiplex, multiplexError, multiplexTimeout, openChannel, pingWebSocket, remoteTimeout, removeChannel, sendResponse, setConnectTimeout, setLocalTimeout, stop, updateProperties

Enumerations

CloseReason

RPF_CLOSE_GRACEFUL = 0

Graceful shutdown, initiated by peer.

RPF_CLOSE_UNEXPECTED = 1

Unexpected shutdown by peer.

RPF_CLOSE_ERROR = 2

Close due to socket exception.

RPF_CLOSE_TIMEOUT = 3

Close due to timeout.

Constructors

RemotePortForwarder

RemotePortForwarder(
    SocketDispatcher & dispatcher,
    Poco::SharedPtr < Poco::Net::WebSocket > pWebSocket,
    const Poco::Net::IPAddress & host,
    const std::set < Poco::UInt16 > & ports,
    Poco::Timespan remoteTimeout = Poco::Timespan (300, 0),
    SocketFactory::Ptr pSocketFactory = new SocketFactory
);

Creates the RemotePortForwarder, using the given socket dispatcher and web socket, which is used for tunneling data. Only the port numbers given in ports will be forwarded. The web socket must have already been connected to the reflector server.

Destructor

~RemotePortForwarder

~RemotePortForwarder();

Destroys the RemotePortForwarder and closes the web socket connection.

Member Functions

getConnectTimeout

const Poco::Timespan & getConnectTimeout() const;

Returns the timeout for connecting to local ports.

getLocalTimeout

const Poco::Timespan & getLocalTimeout() const;

Returns the timeout for the forwarded local ports.

remoteTimeout

const Poco::Timespan & remoteTimeout() const;

Returns the timeout for the remote connection.

setConnectTimeout

void setConnectTimeout(
    const Poco::Timespan & timeout
);

Sets the timeout for connecting to local ports.

setLocalTimeout

void setLocalTimeout(
    const Poco::Timespan & timeout
);

Sets the timeout for the forwarded local ports.

stop

void stop();

Stops the RemotePortForwarder.

updateProperties

void updateProperties(
    const std::map < std::string, std::string > & props
);

Transmits properties (key-value pairs) to the remote peer.

closeWebSocket protected

void closeWebSocket(
    CloseReason reason,
    bool active
);

demultiplex protected

bool demultiplex(
    SocketDispatcher & dispatcher,
    Poco::Net::StreamSocket & socket,
    Poco::Buffer < char > & buffer
);

demultiplexError protected

void demultiplexError(
    SocketDispatcher & dispatcher,
    Poco::Net::StreamSocket & socket,
    Poco::Buffer < char > & buffer
);

demultiplexTimeout protected

void demultiplexTimeout(
    SocketDispatcher & dispatcher,
    Poco::Net::StreamSocket & socket,
    Poco::Buffer < char > & buffer
);

forwardData protected

bool forwardData(
    const char * buffer,
    int size,
    Poco::UInt16 channel
);

multiplex protected

bool multiplex(
    SocketDispatcher & dispatcher,
    Poco::Net::StreamSocket & socket,
    Poco::UInt16 channel,
    Poco::Buffer < char > & buffer
);

multiplexError protected

void multiplexError(
    SocketDispatcher & dispatcher,
    Poco::Net::StreamSocket & socket,
    Poco::UInt16 channel,
    Poco::Buffer < char > & buffer
);

multiplexTimeout protected

void multiplexTimeout(
    SocketDispatcher & dispatcher,
    Poco::Net::StreamSocket & socket,
    Poco::UInt16 channel,
    Poco::Buffer < char > & buffer
);

openChannel protected

bool openChannel(
    Poco::UInt16 channel,
    Poco::UInt16 port
);

pingWebSocket protected

void pingWebSocket();

removeChannel protected

void removeChannel(
    Poco::UInt16 channel
);

sendResponse protected

void sendResponse(
    Poco::UInt16 channel,
    Poco::UInt8 opcode,
    Poco::UInt16 errorCode
);

Variables

webSocketClosed

Poco::BasicEvent < const int > webSocketClosed;

Fired when the web socket has been closed.

The event argument will indicate the reason for the close. See the CloseReason enum for values and their meanings.

Securely control IoT edge devices from anywhere   Connect a Device