I'm developing an app for remote monitoring of a small power plant. The idea is to keep the remote connection all the time.
We hava a small PC with broadband connection and in addition 3G/4G modem attached.
Checking the connectivity when I have broadband is quite easy for me.
fist I check if the interface that Im using is up, and then just with simple web client i check the response from google or any other site that I assume that should be online :-)
Im using System.Net.NetworkInformation.NetworkInterface.*
Then if there is no connection over the lan network Im connecting to 3G modem and starting 3G connection.
The problem is how to check if my lan connection again got the internet connection and disconnect 3G modem? How to check that particular interface from C# code that it has internet access?
Can I make some manual routing trough the interfaces, or its done somewhere inside the OS it self?
Some advice? Someone has got similar project?
Well you could fetch the Lan connection profile with the same library as the Profile Name is "Ethernet" and then to check you'll first need to connect to a LAN connection and then check and if the connection has internet access the stay else you'll have to switch back. I tried it it takes roughly 30 seconds to do a full route
Related
I have created a C# application with a login form (I use SQL Server database and SSMS). The database is on my PC, when I run the program on another PC which is in the same network as mine, everything works fine, but when I connect one of the laptops on another network, an error occurs: "The path wasn't found".
Is it possible to connect with the server remotely, via internet or something,
without having to be on the same network?
I already have:
Opened tcp and udp ports
Allowed SQL Server ports in Windows Firewall
Added an inbound rule for tcp (port 1433) and udp (port 1434)
Allowed remote connections
Here is my connection string:
Data Source=<server name>;Initial Catalog=Name;User ID=Minko;Password=Password1
This is not a programming question, but a Networking one.
To have a server reachable in the internet, is a costly mater. The static IP adress alone will cost a pretty penny, never mind actuall hardware.
On a small/no budget, VPN is perhaps the only way. Via VPN you can connect two local Networks (the home side of the Routers), allowing devices to talk as if they were physically in the same network.
No change to the programm is nessesary. If it works local, it works over VPN. The network classes do not care if the target is on the same computer, the same Switch or the Voyager probes.
The user will have to connect to teh VPN endpoint you have to provide - and usually can provide for cheap with any decent Router.
First off you should definitely change that PW.
Also - you make the comment that you are trying to use the same program to connect from a different network - implying that you haven't changed the IP address...
Are you sure you're using your public IP address? (Not your local network one that will start with 10. / 172. / 192.
Make sure you're using your public IP address... if you do this even if you're on the same network it will treat it as if you're not. It seems to me like you're still trying to use the local network's IP.
If it persists make sure you can reach the PC itself: ping ip-of-host in Powershell.
Connecting C# with SQL Server Database in a Local Area Network (LAN)
Try these steps one by one :
1- Find your public IP address using ( www.whatismyip.com ) for example.
2- Check that you can connect to the database using the public IP. To do that go to SSMS, and in the server name try to use IP-address only, or "IP-address\[instance-name]. If doesn't work, then you have to fix this first. Check this: https://dba.stackexchange.com/questions/62165/i-cant-connect-to-my-servers-sql-database-via-an-ip-address
3- When step 2 works, then you can use the "IP-Address\[instance-name]" in the connection string.
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?
Is there a way to find out whether the current chat session is happening through a VPN connection programatically (using either C# or Java) ?
I don't have access to network tools to do a R&D ( first of all not sure whether it can be tracked live), hence i haven't tried anything.
Any help/pointers/directions will of great help.
Thanks
I believe it would depend on how the VPN is set up.
If the VPN is connected using a software endpoint then it will normally have a simulated network adaptor that you could most likely find the name of (the hardware drivers display name not the connection name) and compare it to a list of known VPN network adaptors.
If the VPN is connected using a hardware endpoint like a firewall or other dedicated network device then there may be no way to tell without some sort of man in the middle hardware approach.
this is my first question here, after searching and reading through many places I have not choice but to ask.
I have a C# application that receives data from a GPS device and stored in a database, I need now is to send a string that contains commands which the device should be interpreted.
This device connects to the Internet over GPRS, I haven't idea how to send this packet over TCP over GPRS because the IP is dynamic.
I hope any suggestions or ideas on how to solve this.
Best regards.
You should do it the other way around - the device should poll the server for instructions. Just make sure the server is accessible.
As you have specified that you have developed a C# application to read the GPS data through GPRS that means you are running C# application on a public/static IP.
Nwo as soon as you get a request from the GPRS client, you get the DHCP IP address of the remote endpoint too.
Once you have that endpoint and socket open, you can transmit any data to the GPS device back.
Assuming that your GPS device is having some microcontroller to drive the GSM/GPRS modem.
I'm going to make an assumption here that the 'Device' is some kind of mobile phone connected to a standard GSM network?
If it is, then the short version of the story is "Forget it" even if the IP wasn't dynamic, you simply wouldn't be talking to the IP of your device, you'd actually be talking to the IP address of your providers GGSN, and for a standard consumer connection this is going to be where the buck stops.
Now that said, IF you have the budget, and all your devices (Assuming multiple ones) are with the same carrier, then you can approach the carrier and request a dedicated APN (Access point name) essentially what this is , is the mobile network equivalent of a DNS record, or at least similar enough to use that analogy anyway.
When you set up your data connection on your device you may recall having to enter something like 'pp.vodafone.com' or 'INGhub411.o2-uk.inbound' we'll this is your actual APN, and if you have a custom one they your devices can be set up so that the IP the presents itself at the GGSN actually has a static route back to the individual device in the suppliers GSM network.
As a general rule of thumb however on consumer grade connections this is not enabled and hence there is no ingress available to the individual device.
As zmbq says, the ONLY option you have is for the device to keep polling the server on a regular basis, and yes unfortunately that is going to be very unforgiving on the battery.
of course there is one other way of approaching this, and that's to have the device open a socket directly to your server then keep that socket open. Once the socket is open, 2 way communication can be performed across the link, unfortunately your going to also have to write all the code to manage this connection including, but not limited to monitoring the connection to make sure it's still open and re-establishing it if it's not, something which is incredibly important on a mobile device.
I'm trying to get a connection via TCP sockets from my Phone that is plugged via USB to the PC. It does not seem to work. The Socket.ConnectAsync returns a Success, so the hostname (name of my PC) is correctly resolved. However, the first Socket.SendAsync ends up in a Connection Reset.
It works with the emulator and if the PC and phone are in the same private WiFi network, but never via the USB connection.
This is kind of strange, since HTTP traffic seems to work quite well: The phone's browser can connect to my PC's webserver (with both PC and phone beeing offline, just connected via USB) and a small test app can connect via HTTP (WebClient) to the PC, like asked in this SO question here.
So my question is, as there must be some security restriction that I did not discover yet, or some technical restriction: How can I get it to work, and if not, why?
Thanks in advance for any help with this!
Have you tried doing a connection using the Socket class to the web server (ie. port 80) on your computer?
I'm pretty sure the USB Connection Sharing for WP7 is restricted on the ports that it actually shares. I could be wrong, of course, but this would explain your situation.