Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

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

$
0
0
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. My own programlog gives me following:
2014-01-20 10:50:52 Starting application

2014-01-20 10:51:03 StartReceive fired off!

2014-01-20 10:51:03 port_RequestReceived: '127.0.0.1:7283'

2014-01-20 10:51:03 port_RequestReceived: '127.0.0.1:7284'

2014-01-20 10:51:06 Sending pan/tilt command.

2014-01-20 10:51:06 port_RequestReceived: '127.0.0.1:7291'

2014-01-20 10:51:07 port_RequestReceived: '127.0.0.1:7292'

2014-01-20 10:51:07 En befintlig anslutning tvingades att stänga av fjärrvärddatorn StackTrace:    at Renci.SshNet.Session.WaitHandle(WaitHandle waitHandle)
   at Renci.SshNet.Channels.Channel.WaitHandle(WaitHandle waitHandle)
   at Renci.SshNet.Channels.ChannelDirectTcpip.Open(String remoteHost, UInt32 port, Socket socket)
   at Renci.SshNet.ForwardedPortLocal.<>c__DisplayClass3.<InternalStart>b__2()

2014-01-20 10:51:07 port_RequestReceived: '127.0.0.1:7293'

2014-01-20 10:51:07 Session is not connected. StackTrace:    at Renci.SshNet.Channels.ChannelDirectTcpip.Open(String remoteHost, UInt32 port, Socket socket)
   at Renci.SshNet.ForwardedPortLocal.<>c__DisplayClass3.<InternalStart>b__2()

2014-01-20 10:51:07 The underlying connection was closed: An unexpected error occurred on a receive. StackTrace:    at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at IpCamera.Library.Cameras.MjpegIPCamera.RespCallback(IAsyncResult ar) in c:\Projekt\TFS\IpCamera\IpCamera.Library\Cameras\MjpegIPCamera.cs:line 156

Any hunch? Any ideas? Any?

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>