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.
Related
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.
I have a functioning extension that communicates with native host C# app. Looking for a way to automatically re-establish a connection with the C# app after I close and re-open it. Any help greatly appreciated.
Native messaging means only Chrome can start a host instance when it "connects". It's a misnomer, since connect() means "launch a new copy and talk to it".
There is no way to "attach" to an already-running process. If you close the host, stdio pipe is broken the Port object fires onDisconnect event. Then you need to re-launch the host from the extension to be able to talk to it.
How about asking the server if it's still here (i.e. once every 30 seconds)
if you get no answer given a certain delay (=> timeout) drop the connection and create a new one.
Th delay must not be too fast, to avoid resettong connections when there is only a 'lag spike'
I'm using this sample code by CodeProject to connect to GPRS in a Windows Mobile in C#.
I tried the code and it works fine. However, sometimes I get a message saying "ConnectionLinkFailed" and I can't connect to GPRS.
I must wait some time in order to being able to connect again. Rebooting doesn't solve the problem either.
Does anyone knows how to avoid this exception?
Thanks for any help!
The MSDN site only states:
CONNMGR_STATUS_CONNECTIONLINKFAILED The connection link was prematurely disconnected.
There is no further description. I assume you have a problem with your provider. Beside from that, I do not rely on Connection Manager (CM) connections. Soemtimes it states a connection is available, but it is not in real as CM uses a cached information.
Normally, for getting a connection, you only have to issue a http request. CM will choose the right connection. Usa of CM API is only usefull if you need to switch between different connections with same destination network. But this i normally not the case, as you will have normally only a WiFi and one GPRS connection to internet and WiFi is selected prior to GPRS (due to costs).
What is the scenario that makes you think you have to use CM?
I have a problem, I've developed a Client and Server wrapper for my personal use, but unfortunately due to insufficient knowledge in network programming, I have TIME_WAIT problems during connect on the client. My client tries to make multiple connections to the same host within short period of time now, I have found out that the main reason for that is because I'm trying to reuse the socket and it goes to TIME_WAIT state because I'm closing the connection without graceful shutdown. I would like to know the correct pattern to close connection using .NET sockets in case I'm using 'Async' APIs intensively i.e. functions like ConnectAsync, AcceptAsync, SendAsync, ReceiveAsync, DisconnectAsync (DisconnectAsync - reuses socket)
I have found out that it is impossible to prevent TIME_WAIT. Either server or client will have the problem any way, depending only on who initiates a closure of the connection first. If it's the client who closes the connection, there will be no TIME_WAIT on server. If it's the server who closes first, than there will be no TIME_WAIT on client. So the only option that is left to do is using SO_REUSEADDR, but in this case it is still impossible to use the reused address for contacting previously disconnected host
You can use SO_REUSEADDR on the socket to get around this. See Socket.SetSocketOption for details, it's the ReuseAddress option you need to set.
By the way you don't really mean reuse the socket do you? once you get an error, you have to close it and open a new one.
I've got a c# WINDOWS Application that is multi-threaded. It is my understanding that in a web environment, connections are pooled automatically. It is also my understanding that in a Windows app, this is not the case. Therefore, for a Windows app, the same connection should be used and not closed after each call, but instead closed when the app shuts down.
I'm curious though - is my correct? If it is, can two threads use the same connection to get a dataset from the DB at the same time or is that functionality queued up?
Thanks
The Connection Pooling is one feature of ADO.NET. Therefore the connections are already pooled. Not only in the web environment.
http://www.ondotnet.com/pub/a/dotnet/2004/02/09/connpool.html
It is my understanding that in a web
environment, connections are pooled
automatically. It is also my
understanding that in a Windows app,
this is not the case.
No, this is wrong, as m3rLinEz pointed out. Connections are always pooled.
Therefore, for a Windows app, the same
connection should be used and not
closed after each call, but instead
closed when the app shuts down.
You could keep a connection open for the duration of the application in a monolithic WinForms app. But it's better to use the standard pattern of opening/closing connections whenever you need them. Connection pooling means you won't notice a performance difference. And your data access code will be compatible with server applications such as ASP.NET.
If it is, can two threads use the same
connection to get a dataset from the
DB at the same time or is that
functionality queued up?
No. The ADO.NET classes (connection, command etc) are not thread-safe and should not be shared between threads without synchronisation. But as noted above, you should prefer the standard pattern for data access.
ok - so this assumption of mine was brought on by observation: When I tried a win app setup in the typical pool fashion, I always experience a 3-5 second delay while a real connection is established to the remote server. Even when I did an open, then a close, the next query would always have this delay.
When the server connects, it obviously doesn't establish a connection for each connection in the pool. Also, is the pooling mechanism smart enough to grab a connection that it knows is already open or is it possible for it to simply grab any random connection?
What is the default max connections in the pool?