An established connection was aborted by the software in your host machine - ForwardedPortLocal

Jan 20, 2014 at 8:20 AM
Edited Jan 20, 2014 at 12:48 PM
Hi!

At the moment I am a bit unsure if it is due to using the ForwardedPortLocal and that my requests to the server side not always turns out to be ok, or how I should but it.

Have created a camera surveillance software that utilise the Renci SshNet library for creating a port forwarding to a connected camera on the server side.

It seems as long as I only let the remote side to send data to client side it seems to work out ok. No error throws back, but If I try to send commands to the device on the server side it tends to maybe work the first time very well and the second time, an suddenly it throws this error, and when I log the error on the client side I get this stacktrace:
at Renci.SshNet.Session.SocketRead(Int32 length, Byte[]& buffer)
   at Renci.SshNet.Session.Read(Int32 length)
   at Renci.SshNet.Session.ReceiveMessage()
   at Renci.SshNet.Session.MessageListener()
The client side sends different commands (over http) to the connect device (connected with WIFI to the server)), and the client side reads from the server side on http (an MJPEG-stream).

Section for creating the forwarded port (at the moment only one device is used.)
        private static Random _rnd = new Random(); 
        private void ProcessCameras()
        {
            int addrnr = 1;

            foreach (IPCamera camera in _cameras)
            {
                string addr = string.Format("127.0.0.{0}", addrnr);

                // int rndport = _rnd.Next(49152, 65535); // IANA suggests the range 49152 to 65535 for dynamic or private ports.
                // IPEndPoint ep = new IPEndPoint(IPAddress.Parse(addr), rndport); 

                IPEndPoint ep = new IPEndPoint(IPAddress.Parse(addr), 3333); 
                
                ForwardedPortLocal port = new ForwardedPortLocal(ep.Address.ToString(), (uint)ep.Port, camera.RemoteLocalEndpoint.Address.ToString(),(uint)camera.RemoteLocalEndpoint.Port);
                addrnr += 1;

                _client.AddForwardedPort(port);

                port.Start();
                port.Exception += PortException;
                port.RequestReceived += port_RequestReceived;

                camera.LocalEndPoint = ep;
                camera.Index = _cameras.IndexOf(camera);
                camera.StartReceive();
            }

        }
And here is how I initiate the sshclient
 public void Connect()
        {

            try
            {

                if (_client == null)
                {

                    if (_connectiontype == ConnectionType.Password)
                    {
                        _client = new SshClient(_host, _port, _user, _password);
                    }

                    if (_connectiontype == ConnectionType.PrivateKey)
                    {
                        _client = new SshClient(_host, _port, _user, _privatekey);
                    }

                    _client.ConnectionInfo.Timeout = new TimeSpan(0, 0, 15); 
                    _client.KeepAliveInterval = new TimeSpan(0,0,10); 
                    _client.ErrorOccurred += SshClientErrorOccurred;
                    _client.Connect();

                    var e = new StateChangedEventArgs();

                    if (_client.IsConnected)
                    {
                        e.Connected = true;
                        StateChanged(this, e);
                        ProcessCameras();
                    }
                    else
                    {
                        e.Connected = false;
                        StateChanged(this, e);
                    }

                }
            }
            catch (Exception ex)
            {
                ErrorRaised(this, new ErrorEventArgs(ex)); 
            }
I have not been able to log on the server side yet to see whats happend. But Im a bit confused why it always only dies when sending commands, not when Im only reading the MJPEG-stream.

Edited: I added the project to my soultion to be able to debug it better. Anyway when I enable the diagnostic, I get this:
...
SshNet.Logging Verbose: 1 : Server version '2.0' on 'dropbear_0.52'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'KeyExchangeInitMessage': 'SSH_MSG_KEXINIT'.
SshNet.Logging Verbose: 1 : SendMessage to server 'KeyExchangeInitMessage': 'SSH_MSG_KEXINIT'.
SshNet.Logging Verbose: 1 : SendMessage to server 'KeyExchangeDhInitMessage': 'SSH_MSG_KEXDH_INIT'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'KeyExchangeDhReplyMessage': 'SSH_MSG_KEXDH_REPLY'.
SshNet.Logging Verbose: 1 : SendMessage to server 'NewKeysMessage': 'SSH_MSG_NEWKEYS'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'NewKeysMessage': 'SSH_MSG_NEWKEYS'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ServiceRequestMessage': 'SSH_MSG_SERVICE_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ServiceAcceptMessage': 'SSH_MSG_SERVICE_ACCEPT'.
SshNet.Logging Verbose: 1 : SendMessage to server 'RequestMessageNone': 'SSH_MSG_USERAUTH_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'BannerMessage': 'SSH_MSG_USERAUTH_BANNER'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'FailureMessage': 'SSH_MSG_USERAUTH_FAILURE'.
SshNet.Logging Verbose: 1 : SendMessage to server 'RequestMessagePassword': 'SSH_MSG_USERAUTH_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'SuccessMessage': 'SSH_MSG_USERAUTH_SUCCESS'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelOpenMessage': 'SSH_MSG_CHANNEL_OPEN : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelOpenConfirmationMessage': 'SSH_MSG_CHANNEL_OPEN_CONFIRMATION : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelEofMessage': 'SSH_MSG_CHANNEL_EOF : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelOpenMessage': 'SSH_MSG_CHANNEL_OPEN : #1'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelEofMessage': 'SSH_MSG_CHANNEL_EOF : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelCloseMessage': 'SSH_MSG_CHANNEL_CLOSE : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelCloseMessage': 'SSH_MSG_CHANNEL_CLOSE : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelOpenConfirmationMessage': 'SSH_MSG_CHANNEL_OPEN_CONFIRMATION : #1'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #1'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelOpenMessage': 'SSH_MSG_CHANNEL_OPEN : #2'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelOpenConfirmationMessage': 'SSH_MSG_CHANNEL_OPEN_CONFIRMATION : #2'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #2'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #2'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelOpenMessage': 'SSH_MSG_CHANNEL_OPEN : #3'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelEofMessage': 'SSH_MSG_CHANNEL_EOF : #2'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelCloseMessage': 'SSH_MSG_CHANNEL_CLOSE : #2'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelCloseMessage': 'SSH_MSG_CHANNEL_CLOSE : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelEofMessage': 'SSH_MSG_CHANNEL_EOF : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #1'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelOpenMessage': 'SSH_MSG_CHANNEL_OPEN : #4'.
SshNet.Logging Verbose: 1 : SendMessage to server 'DisconnectMessage': 'SSH_MSG_DISCONNECT'.
...
Jan 23, 2014 at 6:12 PM
Could this be an reason to why the ssh-server drops the connection, an SSH_MSG_CHANNEL_CLOSE to an already closed channel?

bump
Jan 24, 2014 at 8:44 AM
Have identified the cause to why dropbear_0.52 disconnects my application now and then. After some work I was able to get a log from the remote device and could see that SSH.NET sends an EOF with wrong channelnumber, (unknown channel 1) which makes dropbear to exit after auth.
authpriv.info dropbear [3586] exit after auth (admin): EOF for unknown channel 1