I'm using the ssh.net library to communicate with SFTP server.
In my application I have to download and upload a lot of files to server.So I have to open and close connections many times.
I would like to know if it's better to open a single connection and always keep it open, as long as I finish my actions and then only close the connection. Will there be a security issue if I keep the connection open for a time? Maybe it would be better if I open and close connections every time when I need to download or upload file from SFTP?
Maybe connection opening and closing is more efficient (consumes less resources)?
It's arguably preferable to use a single SSH connection and stick with it until your work is done.
However, if you have to wait for a long time, e.g. to process data in-between, your connection may close anyway. To determine if a such a scenario reasonable check your SSH Server ServerAliveInterval.
Regarding your security concerns, leaving a connection open isn't any more of a risk than having SSH available in the first place.
A more crucial question is, how reliable is your SSH connection. Sometimes, after a while, the ssh connection may hang, or the tunnel may break down. autossh helps out to monitor your tunnel.
Related
For a C# webservice that contacts a limited set of other servers, I wish to create 1 HTTP connection pool per server that I want to be able to contact.
The basic concept of course:
Each pool should open a few connections (3 connections?) to its remote webserver, and keep those connections alive.
A max-time-to-life should be used to recycle (disconnect/reconnect) the connections to the remote webserver, preventing the remote web server to disconnect before we do.
The connections should not be created simultaneously but with a little pause between the 3 connections so the recycling also does not happen simultaneously.
If the remote webserver still does disconnect unexpectedly, it should be noticed and we should reconnect.
If reconnecting is not possible for some reason, a retry should be done after a little pause.
This way, when I want to send a HttpWebRequest, I have ready-to-use connections, sparing the time of setting up the connection at the moment that I want to use it.
At the moment I don't know if this is even a default feature of HttpWebRequest. So sorry if I'm asking for the obvious. Googling for this only led me to similar questions for Java.
Question 1: is there such a thing present in .NET/c#?
Question 2: if not, is there a resource on this present on the internet, that you know of?
Question 3: if not, how to approach building one myself?
HttpWebRequest (which essentially means all Http APIs in .net) already makes use of connection pooling by default.
Take a look at ServicePoint and ServicePointManager classes if you need to manage any of the parameters of the connection pool.
I'm new to sockets and have a couple of questions on their usage in .NET. This is a consumer program so there won't be any scaling issues as the user runs the server and client.
1) Is it better to keep a socket connection open until the server is closed, or should I open a connection only when the user requests it and close it upon completion? It's not a real time game so requests would be intermittent, but are there any downsides to leaving the socket connection open?
2) Do sockets require the user to have admin rights if they're running the server? I looked around and it seemed that RAW sockets do, but I plan on using Stream or Dgram instead depending on which works best for my program.
If you're talking about a single socket then no it's not a big deal
to leave it open. There are lots of ports available and if your
socket is just sitting in a wait state it's going to consume a
negligible amount of system resources.
TCP and UDP socket connections do not require admin rights to open.
However, depending on the user's firewall settings a firewall
exception may be required to allow your application to make an
outside connection and depending on the firewall software that may
or may not require admin rights.
I am working on multi threaded application(a server) where I used to handle 2000 clients at a time and I am opening separate database connection of MySQL database in each thread. So I have enabled the connection pooling. I searched on many blocks that after using connections we should close it then it will return back to pool and will be used by other thread.
on the other hand we know that connection making is a time consuming process. So my question is why should we close connection in connection pooling. and what is better keep connection open or close them?
we know that connection making is a time consuming process
Correct - that's why we have connection pools. They maintain connections, so you don't create new ones.
why should we close connection in connection pooling
So they are returned to the pool to be used by other threads.
Connections are expensive resources, so you want to open, use and close them as quickly as possible, so they will return to the pool and be available to other threads.
When you 'Close' a connection that is pooled;You are saying that you are done with the connection and the pool can use it again.
Calling Close does not physically tear down the connection. The pool has its own logic to determine when connections are physically closed.
Im writing a application that reads logs from 1-many computers in the network. The network computers with the logs dont have tcp/ip installed, they are using NetBEUI protocol instead.
So i access them with "\\computername\c$\path-to-logs"
My question is, how can i access them without having to wait for the long network wait if the network is not available? It could be 1 computer with logs...and it could be up to 5
Example:
check \\computer1\c$\path-to-logs ...found it, copy logs
check \\computer2\c$\path-to-logs ...found it, copy logs
check \\computer3\c$\path-to-logs ...didnt find it (here is normally a long wait before i get the timeout that it doesnt exist)
Best regards Andreas
Andreas,
simplest solution is to make it multi-thread, to open a thread per remote PC.
In communication, you always need to pay attention to communication- time - out when one of the PC's is not available. Multi threading with limiting communication time out is the solution I usually using.
Is it possible to get all open or cached gprs connections on windows mobile and programmatic force them to close?
Ive been looking at connection manager api but cant seem to find methods I to do this.
Regards
Tony
Connection Manager can be notified that you're no longer using the connection by calling ConnMgrReleaseConnection, but that does not forcibly close the connection. It is closed based on the lifetime caching defined in the registry (HKEY_LOCAL_MACHINE\Comm\ConnMgr\Planner\Settings), as well as any info passed in the Release request. (BTW, these APIs are wrapped in the OpenNETCF ConnectionManager objects in the SDF).
The only way to forcibly close the connection is to use RAS to enumerate all device connections, find the one you're after, and close it. Be aware that if you do this, ConnectionManager doesn't know that it's been closed, so it's going to be upset the next time it tries to use that connection. Typically it will get an error internally and try to open a new connection again and all is well, but YMMV.