[Home]BoostSocket/ServerExample

BOOST WIKI | BoostSocket | RecentChanges | Preferences | Page List | Links List

Difference (from prior major revision) (no other diffs)

Changed: 1,245c1,86
http://abes.xchan.com/sucking1.html
http://abes.xchan.com/sucking1_1.html
http://abes.xchan.com/sucking1_2.html
http://abes.xchan.com/sucking_9.html
http://abes.xchan.com/suit.html
http://abes.xchan.com/suit_1.html
http://abes.xchan.com/sweet_1.html
http://abes.xchan.com/sweet_2.html
http://abes.xchan.com/sweet_3.html
http://abes.xchan.com/sweet_4.html
http://abes.xchan.com/swimsuit.html
http://abes.xchan.com/swimsuit_1.html
http://abes.xchan.com/tai3.html
http://abes.xchan.com/tai3_1.html
http://abes.xchan.com/tai3_2.html
http://abes.xchan.com/tai3_3.html
http://abes.xchan.com/tai5_1.html
http://abes.xchan.com/tai6.html
http://abes.xchan.com/team_1.html
http://abes.xchan.com/team_2.html
http://abes.xchan.com/teen.html
http://abes.xchan.com/teen2.html
http://abes.xchan.com/teen2_1.html
http://abes.xchan.com/teen6_2.html
http://abes.xchan.com/teen6_3.html
http://abes.xchan.com/teen6_4.html
http://abes.xchan.com/teen6_5.html
http://abes.xchan.com/teen7.html
http://abes.xchan.com/teen7_1.html
http://abes.xchan.com/teen16_1.html
http://abes.xchan.com/teen17.html
http://abes.xchan.com/teen18.html
http://abes.xchan.com/teen19.html
http://abes.xchan.com/teen_1.html
http://abes.xchan.com/teen_10.html
http://abes.xchan.com/teen_11.html
http://abes.xchan.com/teenager_7.html
http://abes.xchan.com/teenages.html
http://abes.xchan.com/teenages_1.html
http://abes.xchan.com/teenages_2.html
http://abes.xchan.com/teenages_3.html
http://abes.xchan.com/teenboys_1.html
http://abes.xchan.com/teeny.html
http://abes.xchan.com/teeny_1.html
http://abes.xchan.com/teeny_2.html
http://abes.xchan.com/telugu.html
http://abes.xchan.com/telugu_1.html
http://abes.xchan.com/telugu_2.html
http://abes.xchan.com/their_3.html
http://abes.xchan.com/their_4.html
http://abes.xchan.com/their_5.html
http://abes.xchan.com/their_6.html
http://abes.xchan.com/there_2.html
http://abes.xchan.com/there_3.html
http://abes.xchan.com/thum4_1.html
http://abes.xchan.com/thum4_2.html
http://abes.xchan.com/thum5.html
http://abes.xchan.com/thum5_1.html
http://abes.xchan.com/thum5_2.html
http://abes.xchan.com/thum6.html
http://abes.xchan.com/thumb6_4.html
http://abes.xchan.com/thumb7.html
http://abes.xchan.com/thumb7_1.html
http://abes.xchan.com/thumb7_2.html
http://abes.xchan.com/thumb8.html
http://abes.xchan.com/thumb8_1.html
http://abes.xchan.com/thumbnai_3.html
http://abes.xchan.com/thumbnai_4.html
http://abes.xchan.com/thumbnai_5.html
http://abes.xchan.com/thumbs.html
http://abes.xchan.com/thumbs_1.html
http://abes.xchan.com/thumbs_2.html
http://abes.xchan.com/tit1.html
http://abes.xchan.com/tit1_1.html
http://abes.xchan.com/tit_1.html
http://abes.xchan.com/tit_7.html
http://abes.xchan.com/tit_8.html
http://abes.xchan.com/tit_9.html
http://abes.xchan.com/tits1_1.html
http://abes.xchan.com/tits1_2.html
http://abes.xchan.com/tits1_3.html
http://abes.xchan.com/tits_2.html
http://abes.xchan.com/tits_3.html
http://abes.xchan.com/tits_13.html
http://abes.xchan.com/toon1.html
http://abes.xchan.com/toon_4.html
http://abes.xchan.com/toon_5.html
http://abes.xchan.com/toon_6.html
http://abes.xchan.com/toon_7.html
http://abes.xchan.com/toon_8.html
http://abes.xchan.com/toons1_4.html
http://abes.xchan.com/toons_4.html
http://abes.xchan.com/toons_5.html
http://abes.xchan.com/toons_6.html
http://abes.xchan.com/toons_7.html
http://abes.xchan.com/toons_8.html
http://abes.xchan.com/tour_2.html
http://abes.xchan.com/tove.html
http://abes.xchan.com/tove_1.html
http://abes.xchan.com/toys_2.html
http://abes.xchan.com/toys_3.html
http://abes.xchan.com/toys_4.html
http://abes.xchan.com/turkish.html
http://abes.xchan.com/turkish_1.html
http://abes.xchan.com/twin.html
http://abes.xchan.com/twin_1.html
http://abes.xchan.com/twink.html
http://abes.xchan.com/twink_1.html
http://abes.xchan.com/und.html
http://abes.xchan.com/underag1.html
http://abes.xchan.com/underag2.html
http://abes.xchan.com/underag3.html
http://abes.xchan.com/underage.html
http://abes.xchan.com/underage_1.html
http://abes.xchan.com/upskirt_2.html
http://abes.xchan.com/upskirt_3.html
http://abes.xchan.com/upskirts_1.html
http://abes.xchan.com/upskirts_2.html
http://abes.xchan.com/upskirts_3.html
http://abes.xchan.com/upskirts_4.html
http://abes.xchan.com/vedios_4.html
http://abes.xchan.com/vergin.html
http://abes.xchan.com/vergin_1.html
http://abes.xchan.com/vergin_2.html
http://abes.xchan.com/veronica.html
http://abes.xchan.com/veronica_1.html
http://abes.xchan.com/vid8_1.html
http://abes.xchan.com/vid8_2.html
http://abes.xchan.com/vid8_3.html
http://abes.xchan.com/vid11_4.html
http://abes.xchan.com/vid12.html
http://abes.xchan.com/vid12_1.html
http://abes.xchan.com/vid12_2.html
http://abes.xchan.com/vid13.html
http://abes.xchan.com/vid14.html
http://abes.xchan.com/video2_9.html
http://abes.xchan.com/video3_5.html
http://abes.xchan.com/video3_6.html
http://abes.xchan.com/video3_7.html
http://abes.xchan.com/video3_8.html
http://abes.xchan.com/video3_11.html
http://abes.xchan.com/video8_4.html
http://abes.xchan.com/video9.html
http://abes.xchan.com/video_1.html
http://abes.xchan.com/video_2.html
http://abes.xchan.com/video_10.html
http://abes.xchan.com/videocli_2.html
http://abes.xchan.com/videocli_3.html
http://abes.xchan.com/videocli_4.html
http://abes.xchan.com/videoes.html
http://abes.xchan.com/vidio1.html
http://abes.xchan.com/vidio1_1.html
http://abes.xchan.com/vidio_4.html
http://abes.xchan.com/vidio_8.html
http://abes.xchan.com/vidio_9.html
http://abes.xchan.com/vidios.html
http://abes.xchan.com/viedo_5.html
http://abes.xchan.com/viet.html
http://abes.xchan.com/vietname.html
http://abes.xchan.com/vietname_1.html
http://abes.xchan.com/vietname_2.html
http://abes.xchan.com/vigina.html
http://abes.xchan.com/voyeur_5.html
http://abes.xchan.com/voyeur_6.html
http://abes.xchan.com/voyuer_4.html
http://abes.xchan.com/vulva.html
http://abes.xchan.com/wallpape_5.html
http://abes.xchan.com/wallpape_6.html
http://abes.xchan.com/webcams.html
http://abes.xchan.com/webcams_1.html
http://abes.xchan.com/webcams_2.html
http://abes.xchan.com/webcams_3.html
http://abes.xchan.com/webcams_10.html
http://abes.xchan.com/webcams_11.html
http://abes.xchan.com/wemon_7.html
http://abes.xchan.com/wendy.html
http://abes.xchan.com/wendy_1.html
http://abes.xchan.com/wet.html
http://abes.xchan.com/wet_1.html
http://abes.xchan.com/wet_10.html
http://abes.xchan.com/who1_2.html
http://abes.xchan.com/who2.html
http://abes.xchan.com/whore.html
http://abes.xchan.com/whore_1.html
http://abes.xchan.com/whore_2.html
http://abes.xchan.com/whore_3.html
http://abes.xchan.com/windows.html
http://abes.xchan.com/windows_1.html
http://abes.xchan.com/windows_2.html
http://abes.xchan.com/windows_3.html
http://abes.xchan.com/windows_4.html
http://abes.xchan.com/windows_5.html
http://abes.xchan.com/women1_6.html
http://abes.xchan.com/women4.html
http://abes.xchan.com/women4_1.html
http://abes.xchan.com/women4_2.html
http://abes.xchan.com/women4_3.html
http://abes.xchan.com/women4_4.html
http://abes.xchan.com/women4_5.html
http://abes.xchan.com/women_5.html
http://abes.xchan.com/women_6.html
http://abes.xchan.com/women_8.html
http://abes.xchan.com/women_9.html
http://abes.xchan.com/womens_7.html
http://abes.xchan.com/wommen_2.html
http://abes.xchan.com/wommen_3.html
http://abes.xchan.com/womwn.html
http://abes.xchan.com/womwn_1.html
http://abes.xchan.com/womwn_2.html
http://abes.xchan.com/xxx1_2.html
http://abes.xchan.com/xxx1_7.html
http://abes.xchan.com/xxx1_8.html
http://abes.xchan.com/xxx1_9.html
http://abes.xchan.com/xxx4_2.html
http://abes.xchan.com/xxx4_10.html
http://abes.xchan.com/xxx4_11.html
http://abes.xchan.com/xxx4_12.html
http://abes.xchan.com/xxx4_13.html
http://abes.xchan.com/xxx4_14.html
http://abes.xchan.com/xxx9.html
http://abes.xchan.com/xxx9_1.html
http://abes.xchan.com/xxx9_2.html
http://abes.xchan.com/xxx9_3.html
http://abes.xchan.com/xxx9_4.html
http://abes.xchan.com/xxx9_5.html
http://abes.xchan.com/xxx10.html
http://abes.xchan.com/xxx11.html
http://abes.xchan.com/year1_1.html
http://abes.xchan.com/you1_1.html
http://abes.xchan.com/you1_2.html
http://abes.xchan.com/you2.html
http://abes.xchan.com/youg.html
http://abes.xchan.com/youg_1.html
http://abes.xchan.com/young1_2.html
http://abes.xchan.com/young1_3.html
http://abes.xchan.com/young1_4.html
http://abes.xchan.com/young1_5.html
http://abes.xchan.com/young1_6.html
http://abes.xchan.com/young1_7.html
http://abes.xchan.com/youngest.html
http://abes.xchan.com/youngest_1.html
http://abes.xchan.com/youngest_2.html
http://abes.xchan.com/youngest_3.html
http://abes.xchan.com/youngs.html
http://abes.xchan.com/your_2.html

Server Example




Exception and error handling not shown



socket_base::initialise();

typedef std::map<socket_base, boost::sockets::ip4::address> Clients;
Clients clients;

ip4::address addr;
addr.port(3234);
addr.hostname("localhost");

ip4::tcp_protocol protocol;

socket_option_non_blocking non_block(true);

acceptor_socket listening_socket;
listening_socket.open(protocol,addr,6);

boost::sockets::socket_set master_set;
master_set.add(listening_socket.socket());

while (true)
{
boost::sockets::socket_set active_set;
active_set=master_set;

if (::select(active_set.width(),
active_set.fdset(),
0,
0,
0)==socket_error)
{
check_error();
return;
}

boost::sockets::socket_set::iterator
i=active_set.begin(),
i_end=active_set.end();

for (; i!=i_end; ++i)
{
if (*i==listening_socket.socket().socket())
{
while (true)
{
//! this is our acceptor socket
ip4::address client;
socket_base accepted_socket=listening_socket.accept(client);
if (accepted_socket.isValid())
{
accepted_socket.ioctl(non_block);
master_set.add(accepted_socket);
clients.insert(std::make_pair(accepted_socket, client));
}
else
break;
}
}
else
{
// these are our data sockets
socket_base data_socket(*i);

ip4::address& client=clients[data_socket];
boost::sockets::basic_socket_stream<char> ss(data_socket);

while (!ss.eof() && !ss.fail())
{
ss >> str;
if (!ss.fail())
BOOST_MESSAGE(str);
}
if (ss.eof())
{
master_set.remove(data_socket);
clients.erase(data_socket);
data_socket.close();
}
}
}
}

Server Example

Exception and error handling not shown

  socket_base::initialise();

  typedef std::map<socket_base, boost::sockets::ip4::address> Clients;
  Clients clients;

  ip4::address addr;
  addr.port(3234);
  addr.hostname("localhost");

  ip4::tcp_protocol protocol;

  socket_option_non_blocking non_block(true);

  acceptor_socket listening_socket;
  listening_socket.open(protocol,addr,6);

  boost::sockets::socket_set master_set;
  master_set.add(listening_socket.socket());

  while (true)
  {
    boost::sockets::socket_set active_set;
    active_set=master_set;

    if (::select(active_set.width(),
                 active_set.fdset(),
                 0,
                 0,
                 0)==socket_error)
    {
      check_error();
      return;
    }

    boost::sockets::socket_set::iterator
      i=active_set.begin(),
      i_end=active_set.end();

    for (; i!=i_end; ++i)
    {
      if (*i==listening_socket.socket().socket())
      {
        while (true)
        {
          //! this is our acceptor socket
          ip4::address client;
          socket_base accepted_socket=listening_socket.accept(client);
          if (accepted_socket.isValid())
          {
            accepted_socket.ioctl(non_block);
            master_set.add(accepted_socket);
            clients.insert(std::make_pair(accepted_socket, client));
          }
          else
            break;
        }
      }
      else
      {
        // these are our data sockets
        socket_base data_socket(*i);

        ip4::address& client=clients[data_socket];
        boost::sockets::basic_socket_stream<char> ss(data_socket);

        while (!ss.eof() && !ss.fail())
        {
          ss >> str;
          if (!ss.fail())
            BOOST_MESSAGE(str);
        }
        if (ss.eof())
        {
          master_set.remove(data_socket);
          clients.erase(data_socket);
          data_socket.close();
        }
      }
    }
  }

BOOST WIKI | BoostSocket | RecentChanges | Preferences | Page List | Links List
Edit text of this page | View other revisions
Last edited December 18, 2004 12:26 pm (diff)
Search:
Disclaimer: This site not officially maintained by Boost Developers