Get data from internet?

Dec 22, 2008 at 8:06pm
Hello i'm trying to make a "track" program.

Example of what i mean

A program that gets "live stock" prices updated second by second. The prices are updated via the program conncecting to the internet.

Is this possible in c++?
If it is which functions should i use?
Last edited on Dec 22, 2008 at 8:46pm
Dec 22, 2008 at 9:04pm
Well...you could use sockets that receives data from a server with the prices...but I don't know exactly how you could get a raw webpage and parse the data. You could try googling it (unless you already have).
Dec 23, 2008 at 8:20am
if it's on Windows, it's done automatically with Win32 api...
Dec 23, 2008 at 6:48pm
if it's on Windows, it's done automatically with Win32 api...


Thanks for the answers :).

George could tell me more about how this works?
Thanks.
Last edited on Dec 23, 2008 at 6:48pm
Dec 23, 2008 at 8:27pm
Here are some pointers on what you're going to want to read more about to get this job done:

You will want to learn about sockets. Sockets will be your portals to the internet. These are what you will use to send and receive data from the internet. If you are on Windows, you want to check out winsock (#include <winsock2.h>). Important: You will need to link to ws2_32.lib to make this compile. If you're getting a ton of linker errors, you probably forgot to include ws2_32.lib in your project. Possible search keywords: winsock, berkeley sockets, network programming. nullterminator.net has a decent c++ tutorial demonstrating a simple client and server application using winsock (http://www.nullterminator.net/winsock.html). You will be building a client that connects to whatever server is providing your stocks.

Once you can send and receive data from the internet, you will need to know how to speak the language of whatever service you're contacting. These languages are called protocols. If you're contacting a website for the stock information, odds are that website will use HTTP (HyperText Transfer Protocol). See "HTTP Made Really Easy" at jmarshall.com for a good tutorial on http (http://www.jmarshall.com/easy/http/). Search for: Http, get request, post request

If you're doing this stuff for fun/knowledge, you should follow the above steps. If you're just trying to get something done for work or as quickly as possible, find a library that will do what you want. I have never used it myself, but the C++ Poco libraries include a HTTPClient object which should get you around the sockets and the http part.

Last thing I'll mention is to make sure that the stock service you're using allows you to grab their information for free. Certain services' terms of service don't allow you to write your own program to grab info from their servers (Try writing a program to search on Google without their permission, for example).
Dec 28, 2008 at 4:40am
Well for one thing, the way that you should do this is definitly with the
Win32 API, but there are some better alternatives to WinSock.

For starters you should look into the WinInet API. This is basically some WinSock-like code wrapped up in a handfull of nice functions. There are a couple of advantages though.
1.) Easier to use than WinSock (too many send() and recv()'s everywhere)
2.) Has built in support for HTTP, HTTPS, FTP, and Gopher protocols (will manage HTTPS' SSL for you)
3.) Easy to parse things such as status codes, header values, and even cookies

So look into these pages:
http://msdn.microsoft.com/en-us/library/aa385483(VS.85).aspx
http://www.differentpla.net/content/2004/02/downloading-from-an-http-server-using-wininet

and see if it suits your needs.

Hope that this helps

SigmaSecurity
Last edited on Dec 28, 2008 at 4:43am
Dec 29, 2008 at 12:14pm
If you like to use linux then use web service with c++.

Andy...
Topic archived. No new replies allowed.