socklibpp::basic_sockstream< _CharT, _Traits > Class Template Reference

Input/Output stream class. More...

#include <sockstream.h>

Inheritance diagram for socklibpp::basic_sockstream< _CharT, _Traits >:

List of all members.

Public Types

typedef _CharT char_type
typedef _Traits traits_type
typedef traits_type::int_type int_type
typedef traits_type::pos_type pos_type
typedef traits_type::off_type off_type

Public Member Functions

 basic_sockstream (const sock &sock_)
 basic_sockstream (const addr_in sin_)
 Construct a stream object and connect it to address _sin using a TCP connection.
bool is_connected () const throw ()
 Return true if the stream is connected.
bool connect (const addr_in &sin_)
 Connect the stream to a given address, calling sockbuf::connect().
bool connect (const std::string &addr_, uint16_t port_)
 Connect the stream to a given address, calling sockbuf::connect().
bool close ()
 Close the connection, calling sockbuf::close().

Detailed Description

template<typename _CharT, typename _Traits = std::char_traits<_CharT>>
class socklibpp::basic_sockstream< _CharT, _Traits >

Input/Output stream class.

This is a convenience class; it doesn't provide detailed control over the connection.

You shouldn't use this with non-blocking sockets, as there's no way to recover from a failed send/receive; this means that every operation on it may block, so you will either use it in a non-interactive program, or in a separated thread.

Here's an example that uses a sockstream object to send a HTTP request and send it to cout.

#include <iostream>
#include <string>
#include <socklibpp/sockstream.h>

using namespace std;
using namespace socklibpp;

int main()
        string hostn, doc = "/";
        cout << "Enter the host address: " << flush;
        if (!(cin >> hostn))
                return -1;
        cout << "Enter the document location (e.g. '/', 'index.html'): ";
        cin >> doc;
        sockstream web;
        if (!web.connect(hostn.c_str(), 80)) {
                cerr << "Host not found" << endl;
                return -1;
        web << "GET " << doc << " HTTP/1.0" << crlf;
        web << crlf;
        // Now read the response
        string response;
        while (getline(web, response))
                cout << response << endl;


httpdump.cpp, and streamechod.cpp.

Constructor & Destructor Documentation

template<typename _CharT, typename _Traits = std::char_traits<_CharT>>
socklibpp::basic_sockstream< _CharT, _Traits >::basic_sockstream ( const addr_in  sin_  )  [inline, explicit]

Construct a stream object and connect it to address _sin using a TCP connection.

sin_ The address to connect.

The documentation for this class was generated from the following file:
Generated on Thu Jan 18 19:26:35 2007 for socklib++ by  doxygen 1.5.1