Sites communication, Sockets and Win32 API

Hi there, I saw a post here from 2008 where a guy asked: "how to get data from internet?".(http://www.cplusplus.com/forum/general/6546/) The question was answerd:
jeffbmartinez (31)
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).


SigmaSecurity (9)
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


Alrigth, here is my doubt: Should I use sockets or this thing about API? I have used already sockets not worring about the protocol used on the connection, we only developed a game. I have no idea what is an 'API' but from SigmaSecurity's answer it looked much more easier. Rigth now I'm searching on what this API thing is, but any comments are valid.
I'd also like to know if sockets are used on every single site on the internet. Because from what I remember there are more possible ways to computers communicate.
Last edited on
Should I use sockets or this thing about API?
Use sockets. But you don't need to use them directly. Checkout Boost TCP Streams: http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/overview/networking/iostreams.html
Topic archived. No new replies allowed.