I'm developing a compact-framework application for a Windows Mobile device to work with SQLServer Server trough 3G.
The problem is that the device disconnects automatically from 3G after some idle time, and i have reconnect manually, this is not bad at all, the customer doesn't need permanent 3G connection, and it extends the battery life.
But... is there any way to check (in c#) if the 3G connection is running and if not, activate it?
My device is an Intermec CN50.
Thanks and excuse my poor English.
I guess you can use Connection Manager's API to do this. Here is an article of using some API in managed code.
You can check the connection status with ConnMgrQueryDetailedStatus and act based on that information.
OpennetCF already did the wrapping for you, if you are willing to use a free 3rd party assembly. Check out their Connection Manager.
Related
I haven't been able to find any resources regarding this, so I thought I'd ask here.
I have an iOS app that I am developing, as well as a C# desktop app. I'm currently able to connect the two by creating a Socket Server on the desktop app, and connecting from the iOS app. This works well, but I'd like to do this without requiring the devices being on the same network. Communicating via Usb (lightning port) seems like the logical choice, but I can't find any resources at all about how to do this. Are there any tools or best practices regarding this, or is this even possible?
Thanks!
Peertalk, an open source library allowing to pass TCP connections through the USB connection without being part of the MFI program. PeerTalk uses the iTunes usbmux system to relay TCP connections across the iOS USB connection.
I wasn't able to use Peertalk, since I'm using Xamarin for my project. However, I spent the last week researching and documenting what I learned, and I posted it as a blog post here
http://thecodewash.blogspot.com/2017/05/communicating-with-your-ios-app-over.html
Hopefully this helps others.
I am working on porting a Windows Phone application to Windows 8 Metro, using the WinRT API. It is a networking app that makes use of sockets on arbitrary ports (different servers use different ports) On the Wp7 platform, I am able to set both requirements and preferences on which network connection type to use when opening up a socket connection. For instance, by default the socket will only connect on WiFi and not the cellular data connection to protect the user from unexpected data use, but the user can not only set it to use the cellular connection, but to use it even if they are connected to wifi. This is useful for instance if the user is on a corporate network behind a firewall using a wifi connection, but the server or port they want to connect to is blocked by the corporate firewall. In this case, the user can tell my app to use the cellular data connection even while connected to WiFi, so that the connection can go through.
So far, on WinRT, I have only been able to get information about the currently active internet connection, and to enumerate through each connection. I don't know, however, how to tell a StreamSocket to prefer connecting via an alternate data connection from the currently active one or if this is even possible. Without this capability, the network firewall scenario above will not be possible from the app's end. The user would have to go to system settings and disable wifi just to work with my app. This is not ideal - my users on Windows Phone love the ability to set this preference without turning wifi on or off.
Is there a method of setting a network adapter preference programatically in WinRT the way it can be done in WP7?
Judging from the (preliminary) documentaion, I don't believe it's possible to do this using the standard APIs, without digging deeply into how sockets are instantiated in WinRT - that is, without doing stuff that would get your app disqualified from the Store anyway.
The whole point of the new and redesigned networking APIs is to allows the user (well, and Windows itself) to set the current connectivity options to how the want them, and allow your app to adapt its network usage patterns to the current capabilities of the network.
Arguably, it is a step back from what was available on WP7. But the argument here is to let the system and the user chose what's more correct at this moment, and have apps adapt to that, instead of having the apps to come up with logic for what network interface to use.
I'd like to turn off GPRS connection when I close my aplication.
I looked for other problems but:
Power On/Off GPRS on windows mobile
When I use OpenNetCF and set radio.RadioState = RadioState.Off; for PhoneRadio I disable all phone module (I could turn off and on but after that user have to type PIN again)
Other solution:
Closing GPRS Connections On Windows Mobile
recommend to use RAS which is deprecated in WinMo and there is no good documentation.
Is there any posibility to turn off GPRS connection in other way (and if its;s possible using managed C# not P/Invoke and winAPI)?
Your application is not responsible for closing the connection, just as it's not responsible for opening it. Under WinMo, the piece that is responsible for connection is the Connection Manager (CM) and, generally speaking, all requests for connection actions goes through it. For example, when you open something like an HttpWebRequest, CM is notified and it opens a connection for you. Closing a connection, is also out of your app's purview. You can tell CM that you no longer require a connection, but CM is looking for all apps, so it's not going to just shut the connection down. It's going to keep it alive for some period in the event it is either in use or might be called by other application.
This is just how it is. You can't end-run around it with one exception. As the answer you link to says, you can use RAS to forcibly close the connection, but it's not something that I'd recommend becasue it can make CM angry and leave things in a indeterminate state.
I have a 3G modem, and the accompanied "Mobile Partner" software really s*cks, and I want to make my own. Currently, I've found out the following:
Sending/Interpreting AT commands
Setting the APN/PIN/Network Registration/...
These things were well-documented on many sites. But now I want to connect, and here the problems start:
If I try to do a ATDT *99#, which should dial the *99# number, I get the message CONNECT. But what do I need to do now? How do I tell windows to use the dial in network?
Is the '*99#' even the number I should dial? (I think so, because it's the default dialing number in the Mobile Partner application, and on OS X on my 3G modem)
I'm writing this program in C#.
Thank you!
Yvan
I doubt that you would need to solve this in code. It's more of a Windows configuration thing.
Most 3G modems install a modem driver - which is what your Provider's software is using to connect.
In Windows Vista / Windows 7, you just go and set up a new Dialup connection, select your 3G Modem, and enter the *99# number.
Edit:
(Replying to question in comments)
If you want to create this connection on just your own, or maybe a handful of computers then I would say it's quicker to do it by hand to set-up. (It takes maybe a minute or two at most following the Networking wizard)
Once the connection is created, then you simply click Connect any time you want to dial the 3G Connection.
I've done this for several USB 3G dongles and built in 3G Modems - they've all worked fine.
I did look for ways to automate creation of Windows Dial-up networking connections, but I can't find any information.
I would suggest creating a new question on Superuser.com or perhaps Serverfault.com which is probably more suited to windows-administration tasks.
I need to able to block any and all connections to my pc from a specific IP address , i know this is possible with a firewall but i need to do this in c#. Any idea how (need code).
Update :
Its a generic C# app not asp.net , target platform is WinXp till Win7
Need more information... if you're talking socket communication, you can simply close the connection to a client as soon as it connects if the IP address is blocked, or process the Connection Request and evaluate there.
Edit: Simplest way for you would probably just be to interact with Windows Firewall API... here's how:
http://www.shafqatahmed.com/2008/01/controlling-win.html
Your question is unclear but I'll try to answer the best I can, within my understanding.
Do you want to control machines from connecting to any port on your machine? if so, you need to control the built-in windows firewall or find yourself a filter driver you can control. In order to write your own filter driver, you must leave the land of managed code, so I am guessing that's not an option.
To learn how to control the firewall, here's a link:
http://www.shafqatahmed.com/2008/01/controlling-win.html
more on google.
Do you want to control remote machines from connection to a port on your machines that your application owns? You cannot do that either (see #1 above). However you can take action after the connection, and close the connection if you don't like the remote IP (check the remote endpoint's IP).
two caveats with this approach:
It doesn't save you from a DoS attack.
You will need to be careful if you need ipv6 support (you can't just check the IPV4 address in that case)
HTH
A "firewall" in c#?
First you would have to access the network interface on a low level, eg.: http://msdn.microsoft.com/en-us/library/ms817945.aspx
Then you have to parse all incoming packets and maybe discard them.
It's not an easy task and I don't recommend you to write a driver and a firewall in C#, because the .NET Framework will be loaded every time you start your machine.
Also traffic parsing can be tricky... I implemented a router/traffic analyzer in C# some time ago and it took me about one year to gain the experience with network programming to gain the knowledge to do this.