Sha256: 507cb92286a225f5f11c3a3137494f95271b008ea3dab0e8ba9954266648efd2

Contents?: true

Size: 1.15 KB

Versions: 16

Compression:

Stored size: 1.15 KB

Contents

//
// blocking_udp_echo_server.cpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#include <cstdlib>
#include <iostream>
#include <asio/ts/buffer.hpp>
#include <asio/ts/internet.hpp>

using asio::ip::udp;

enum { max_length = 1024 };

void server(asio::io_context& io_context, unsigned short port)
{
  udp::socket sock(io_context, udp::endpoint(udp::v4(), port));
  for (;;)
  {
    char data[max_length];
    udp::endpoint sender_endpoint;
    size_t length = sock.receive_from(
        asio::buffer(data, max_length), sender_endpoint);
    sock.send_to(asio::buffer(data, length), sender_endpoint);
  }
}

int main(int argc, char* argv[])
{
  try
  {
    if (argc != 2)
    {
      std::cerr << "Usage: blocking_udp_echo_server <port>\n";
      return 1;
    }

    asio::io_context io_context;

    server(io_context, std::atoi(argv[1]));
  }
  catch (std::exception& e)
  {
    std::cerr << "Exception: " << e.what() << "\n";
  }

  return 0;
}

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
couchbase-3.0.0.alpha.4-x86_64-linux ext/third_party/asio/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp
couchbase-3.0.0.alpha.4-x86_64-darwin-19 ext/third_party/asio/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp
couchbase-3.0.0.alpha.4-universal-darwin-19 ext/third_party/asio/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp
couchbase-3.0.0.alpha.4 ext/third_party/asio/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp
couchbase-3.0.0.alpha.3-x86_64-linux ext/third_party/asio/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp
couchbase-3.0.0.alpha.3-x86_64-darwin-19 ext/third_party/asio/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp
couchbase-3.0.0.alpha.3-universal-darwin-19 ext/third_party/asio/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp
couchbase-3.0.0.alpha.3 ext/third_party/asio/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp
couchbase-3.0.0.alpha.2-x86_64-linux ext/third_party/asio/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp
couchbase-3.0.0.alpha.2-x86_64-darwin-19 ext/third_party/asio/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp
couchbase-3.0.0.alpha.2-universal-darwin-19 ext/third_party/asio/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp
couchbase-3.0.0.alpha.2 ext/third_party/asio/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp
couchbase-3.0.0.alpha.1-x86_64-linux ext/third_party/asio/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp
couchbase-3.0.0.alpha.1-x86_64-darwin-19 ext/third_party/asio/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp
couchbase-3.0.0.alpha.1-universal-darwin-19 ext/third_party/asio/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp
couchbase-3.0.0.alpha.1 ext/third_party/asio/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp