Access to internet with C++

Hi there,
I would like to know how to access internet with a easy C++-program. I'd need it for my AI I'm programming at the moment...
Thanking you in anticipation,
FlashDrive
closed account (S6k9GNh0)
"Internet Access" is provided through "network sockets" which is provided through an API provided by the OS the application is running on. There are various solutions for cross-platform solutions such as Boost.ASIO, a basic wrapper around WinSock, and many others.

Beej's guide sucks and is rather outdated last time I checked. I would suggest trying a wrapper over BSD sockets rather than using BSD sockets directly anyways as BSD sockets proves to be unintuitive now a days.
thanks a lot.
If you might also add a sample code, I'd be very, very happy ^^
closed account (S6k9GNh0)
Eh... using synchronous ASIO which is what I'm familiar with, here's a basic example of an echo server below (which is VERY NAIVE and probably isn't the way to go about network IO):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <boost/asio.hpp>
#include <cstdlib>
#include <iostream>
#include <array>

int main(int argc, char **argv)
{
    using namespace boost;

    asio::io_service ioSrvc;
    asio::ip::tcp::socket ioSocket(ioSrvc);
    boost::asio::ip::tcp::endpoint endpoint(
        boost::asio::ip::address::from_string(argv[1]), atoi(argv[2]));
    std::array<char, 30> ioBuffer;
    ioBuffer.fill(0);

    ioSocket.connect(endpoint);

    for (;;) {
        ioSocket.read_some(ioBuffer);
        std::cout << ioBuffer.data() << std::endl;
        asio::write(ioSocket, ioBuffer);
    }
}


This is untested, make sure it works correctly. ASIO also provide its own examples but a lot of them are out of date apparently.
Last edited on
cool! thx a lot
Topic archived. No new replies allowed.