How to programmatically check Internet bandwidth in VC++? - c++

I need to find the bandwidth available at a particular time. The code must be developed in Visual C++ or in .Net family . If anyone knows how, please help me out.

The only way to check your bandwidth is to actually try to use it, i.e. by downloading a file from somewhere else and measuring the throughput.
Even then it'll only be an approximation, because other network effects will affect the results:
latency
asymmetric upload / download
other traffic

If you mean the current network utilisation, you can call
DeviceIoControl(hDevice, OID_GEN_STATISTICS, ...)
on Vista and above to get the device-specific information. Otherwise, call GetIpStatisticsEx for system-wide information or use WMI's Win32_PerfRawData_Tcpip_NetworkInterface.
Trying to get the "available" bandwidth by attempting to saturate the connection is not a sensible or reliable measure. Just try some of the online speed tests available, and consider that it involves non-scalable bandwidth, and is susceptible to congestion control, QoS and traffic shaping.

Checking the bandwidth will be tricky even by using it. if you try to download data from remote machine X for example and you estimate a figure of N Kbs then how will you know whether that's your bandwidth limitation or the limitation of remote machine X's connection?
You'd need to start simultaneous downloads (or uploads if that's the direction you want to measure) with several remote machines simultaneously and keep increasing the load until the throughput stops increasing.
But as Alnitak said you still won't know what other factors might be affecting the result. Is some other process on your machine using the connection for example? or is the kid next door piggybacking on your wireless LAN and stealing your bandwidth? Maybe that's what you're trying to find out!

Related

How to flush the Windows Event Log to disk?

I have a Windows 7 embedded device which is frequently power cycled like this: a local application writes an entry to the Application event log and a few seconds later it commands the custom power supply to cycle power. A clean Windows shutdown cannot be done. After the device boots back up, I check the Windows event log and notice the last entry missing.
Is there some way to flush the Windows event log to disk so that I don't miss that last entry? The application is written in C++.
Thanks,
Adnan
You have a hardware problem so the best solution is to resolve it in hardware. But moving on.
Use BIOS to ensure computer always starts after a power cycle
You have a hardware tool to perform the reboot. Could you reconfigure that so that rather than doing a hard power cycle while the computer is running, you:
notify the hardware power cycle tool,
perform an orderly shutdown, then
power the computer on again using the hardware power switch?
There is usually a bios setting which allows you to specify the action after a power cycle, e.g.
Leave the computer off,
Turn it on,
Turn it on only if it was on when power was lost.
If you can do this, then you can still do an orderly shutdown and wait for that to complete before powering on again.
Software Solution: Turn off disk write caching
It's not exactly clear what is causing your issue, but the following seem relevant.
Most likely, this is a result of disk write caching either by the disc controller hardware, or by the operating system.
You may be able to turn this off through the Disk Management tool:
http://www.thewindowsclub.com/enable-disable-disk-write-caching-windows-7-8
Software Solution: Flush the disk programmatically
Alternatively, you may be able to flush the disk cache programmatically. This tool may help:
https://superuser.com/questions/833552/manually-flushing-write-cache-on-window
Or indeed with WMI and PowerShell:
https://technet.microsoft.com/en-us/library/dn454975.aspx

google protocol buffers - probability of bit errors and ways to reduce them

I transmit a fairly large amount of google protocol buffer msgs over a VPN over wireless over internet via TCP, and I feel like I get a relatively high error rate (e.g. a boolean field switching from false to true or sth similar). Something between 1 in 10,000 and 1 in 50,000.
Is that possible? Wikipedia states that TCP has a weak checksum, but that this is typically fixed in underlying protocols:
The TCP checksum is a weak check by modern standards. Data Link Layers with high bit error rates may require additional link error correction/detection capabilities. The weak checksum is partially compensated for by the common use of a CRC or better integrity check at layer 2, below both TCP and IP, such as is used in PPP or the Ethernet frame.
Does anyone have any experience what expected error rates should be? If above rate is possible, what would be the recommended / easiest way of fixing it? Duplicating the fields? Sending the message twice? Or is there something else that can be done to increase reliability?
Thanks
No it is not (reasonably) possible. Assuming that you are not suffering a hardware failure (of memory, your network card, etc.), which should be easy to check--does it happen on more than one computer?
Much more likely is that you have an invalid memory access or the like within your application code, or that the data you are sending is simply not what you intended. Try running your code under valgrind or the like.
The idea of duplicating fields as part of normal operation seems absurd: basically nobody does that in the wild, and you shouldn't need to either. There are multiple layers of protection against silent data corruption in your system, so it's most likely a simple (or maybe not-so-simple) application error.
John Zwink's answer is correct in that your results are not reasonable, and fixing at the application layer is a mistake.
The VPN (assuming SW layer) would go bonkers and lose connection if the network card were introducing that many errors.
Try Valgrind, as suggested, to find if your SW is corrupting the buffer.
Also, in case "easy to check" for the memory didn't seem so, a good bet is memtest86, http://www.memtest86.com, which you can stick on a USB drive or CD, and let run overnight or over the weekend.

What is a good hardware setup for programming concurrent and distributed applications?

I don't have the money to build my own uber Blade system but I would like to get into concurrent and distributed programming (think CCR/DSS, Hadoop, Project Voldemort etc.).
I currently have a Q6600 with 4GB with some separate hdds but that's about it. While I can write multi-threaded programs I can not properly test distributed filesystems / key-value stores and look for associated bottlenecks (disk access, network, etc.).
Does anyone have some recommendations? Buying some small cheap boxes and setting up a mini network? Or maybe a single box with two i7's and ESX and a simulated network?
edit:
I'm currently using VirtualBox and VmWare and this does not look good enough for me, correct me if I'm wrong: The hard drives could lock for instance, either because two virtualized machines run on them, or because all hard drive access is channeled through the same hdd controller. The network is entirely virtual, so no real case test here either.
If I go the virtualization route, what would you recommend so I can get as near to 'real-life' as possible?
Virtualise for your distributed system tests. It's much easier to 'pull the plug' on a machine, disconnect the network cable etc.
Sun VirtualBox is an excellent free virtual machine which I've found extremely convenient for development purposes. Most of it is also Open Source, if you're into that.
As for the multi-threaded part, it's actually easier - always test with more software threads than your number of hardware threads. And then, just for fun, do something like writing a 10 GB file to your hard disk, plug/unplug hardware to throw the scheduler off. You'll get surprising results.

Determine network interface bandwidth/type without transferring data

Is there any way in Win32 to programmatically determine the bandwidth of a given network interface without actually transferring any data? I only want to distinguish between different types of interface (e.g. dialup vs DSL vs LAN), so a rough order of magnitude is fine, I don't need to actually measure the bandwidth.
Background to the problem is that my application is very bandwidth-hungry, and I want to display a warning to the user if they try and run it over a low-bandwidth interface, e.g. dialup modem or GPRS modem.
I've looked at some other related questions but if possible I'd like to avoid measuring throughput. GPRS modems in particular may have usage caps and I don't want to eat into a user's allowance - I'd rather detect the poor connection some other way and not actually send any data at all.
I'm most interested in Win32/C++ answers, but any ideas would be gratefully received.
You could use a WMI query, there are of course Win32 functions calls as well, but this query:
Select * from Win32_PerfFormattedData_Tcpip_NetworkInterface
You can use InternetGetConnectedState to determine the type of connection (LAN/Modem/etc). This will tell you if they have a somewhat decent (non-modem) connection without bandwidth transfer.
Unfortunately, you can't really go much beyond that without connecting and transferring data. There is no way for the system to know the bandwidth limitations outside of it's LAN connection - ie: you could connect to your gateway on a LAN directly, and it may have a crappy connection to the outside world. As far as your computer would be concerned, though, it's on a full speed lan connection...
Why not asking the user? He should know.
Your app could cache the information for the network address and only ask again if the network address has changed.

How do you detect dialup, broadband or wireless Internet connections in C++ for Windows?

I have an installation program (just a regular C++ MFC program, not Windows Installer based) that needs to set some registry values based on the type of Internet connection: broadband, dialup, and/or wireless. Right now this information is being determined by asking a series of yes or no questions. The problem is that the person doing the installations is not the same person that owns and uses the computer, so they're not always sure what the answers to these questions should be. Is there a way to programatically determine any of this information? The code is written in C++ (and optionally MFC) for Windows XP and up. .NET-based solutions are not an option because I don't want to have to determine if the framework is installed before our installation program can run.
To clarify, the issue is mainly that wireless and dialup connections are not "always-on", which creates a need for our product to behave a different way because our server is not always available. So a strictly speed-measuring solution wouldn't help, though there is a setting that's speed dependent so that the product doesn't try to send MB of information through a dialup connection as soon as it connects.
[I have no idea how to get exactly the information you asked for, but...] Maybe you could rephrase (for yourself) what you try to accomplish? Like, instead of asking "does the user have broadband or dialup", ask "how much bandwidth does the user's internet connection have" - and then you can try to answer the rephrased question without any user input (like by measuring bandwidth).
Btw. if you ask the user just for "broadband or dialup", you might encounter some problems:
what if the user has some connection type you didn't anticipate?
what if the user doesn't know (because there's just an ethernet cable going to a PPPoE DSL modem/router)?
what if the user is connected through a series of connections (VPN via dialup, to some other network which has broadband?)
Asking for "capabilities" instead of "type" might be more useful in those cases.
Use InternetGetConnectedState API to retrieve internet connection state.
I tested it and it works fine.
I found this document which can help:
http://www.pcausa.com/resources/InetActive.txt
Regarding the question "is the internet connection permanent or not?":
best way would be probably to make the app robust enough to always cope with a non-permanent connection :-) which would work the same with dialup and broadband...
alternatively, maybe you can find out how long the user's internet connection has been established already, and compare with system uptime? If the connection has been online for almost as long as the computer was running, it's probably a permanent connection.
Anyway, these heuristics will probably fail for obscure connection types.
Also, regarding the point about not sending lots of data: if people have a "broadband + low traffic limit" tariff, you shouldn't send lots of data either even if bandwidth allows :-)
Best bet would be to grab the default active network connection, ensure it is an internet connection (ping google.com or similar) and then ask it what type of device it is. You should be able to determine from that what connection the user has.
I'm fairly confident this is possible, but not sure how to go about it though.
I think you should just do a quick connection-speed test. Just download some specific sized files, time how long it takes, and you'll know the speed. I agree with the other guy, don't ask them what type of connection they have, what's more important is the speed. Perhaps next year they come out with 100mbit dialup...do you want everyone using this amazing new device to get the crappy lowbandwidth version of your app?
I would agree with oliver, as you imply: you have the functionality already to cope with connection loss, why not enable it by default.
Broadband connections can get messed up to: routersoftware that freezes (happens a lot to me), or poweradapter that fries, ...