This project is read-only.

ForwardedPortLocal and Connection error when re-conect secondtime to same forwardedport

Apr 10, 2013 at 4:58 PM
Edited Apr 10, 2013 at 5:06 PM
Hello,

first thanks for your great work, with this SSH library.
I need help with ForwardedPortLocal.
I do a comunication with some remote hardware with Modbus protocol and trought SSH tunnel.
When i open the SSH and portforwading, the first time run correctly. But if i try to read a second time, the socket open ok, but is like the portforwading was disappear.

I explain with the steps i do:

1 - I open conection with SSH server (is a freeSHH)
dim SSHClient as SSHClient
SSHclient = New sshClient("1.2.3.4", 555,"sshuser","sshpass")
SSHClient.connect
2 - I do the 1st portforwading
 dim SSHport as ForwardedPortLocal
 SSHport = New ForwardedPortLocal("127.0.0.1", 14011, "192.168.1.11", 14011)
 SSHclient.AddForwardedPort(SSHport)
 SSHport.Start()
3 - Connect a socket on this port and read from the hardware over this location
NetTalk1.TcpIpConnect("127.0.0.1", 14011, NetTalk.TcpIpProtocolType.Tcp, 2000,500)
NetTalk1.ReadAnalog("XMODBUSB", 16, 1, "4", 0, "", "", "", "", "", "", "", True) 
4 - create new ForwadedPortLocal
dim SSHport2 as ForwardedPortLocal
SSHport2 = New ForwardedPortLocal("127.0.0.1", 14012, "192.168.1.12", 14012)
SSHclient.AddForwardedPort(SSHport2)
SSHport2.Start()
5 - I Connect a socket on this port and read from the hardware over this location
NetTalk1.TcpIpConnect("127.0.0.1", 14012, NetTalk.TcpIpProtocolType.Tcp, 2000,500)
NetTalk1.ReadAnalog("XMODBUSB", 16, 12, "4", 0, "", "", "", "", "", "", "", True) 
--> Up here, all well, socket established ok, and data from modbus is readed well and fast, .

BUT...Now, if i try to readt from 1st equipment on FordwardedPortLocal 192.168.1.11:1411, socket established is ok, but any data is received. Also, i debug and when i try to do a
    SSHclient.ForwardedPorts(0).Stop()
    SSHclient.RemoveForwardedPort(SSHclient.ForwardedPorts(0))
Really, the SSHclient.Forwadedports count is always = 2.
I try to do

SSHport2.stop
SSHclient.RemoveForwardedPort(SSHport2)
SSHport1.start

and more, but without succes.

Could anyone help me about the correct way to do this ??


best regards.