端口转发

此类提供了一种将本地端口转发到另一个主机/端口的简便方法。这给了连接到roboRIO USB端口的计算机一个访问以太网连接设备的方法。此类充当原始TCP端口转发器,这意味着您可以转发诸如SSH之类的连接。

转发远程端口

Often teams may wish to connect directly to the roboRIO for controlling their robot. The PortForwarding class (Java, C++) can be used to forward the Raspberry Pi connection for usage during these times. The PortForwarding class establishes a bridge between the remote and the client. To forward a port in Java, simply do PortForwarder.add(int port, String remoteName, int remotePort).

@Override
public void robotInit() {
   PortForwarder.add(8888, "wpilibpi.local", 80);
}
void Robot::RobotInit {
   wpi::PortForwarder::GetInstance().Add(8888, "wpilibpi.local", 80);
}
wpinet.PortForwarder.getInstance().add(8888, "wpilibpi.local", 80)

重要

您**不能**使用小于1024的端口作为本地转发端口。同样重要的是要注意,您不能使用完整的URL(http://wpilibpi.local),而只能使用IP地址或DNS名称。

移除转发的端口

要停止在指定端口上的转发,只需调用“ remove(int port)”,port为端口号,即可。如果在未转发的端口上调用``remove()``,则不会发生任何事情。

@Override
public void robotInit() {
   PortForwarder.remove(8888);
}
void Robot::RobotInit {
   wpi::PortForwarder::GetInstance().Remove(8888);
}
wpinet.PortForwarder.getInstance().remove(8888)