-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathudp_client.cpp
36 lines (30 loc) · 855 Bytes
/
udp_client.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) 2015
// Author: Chrono Law
#include <std.hpp>
//using namespace std;
using std::cout;
using std::endl;
using std::vector;
#define BOOST_ASIO_DISABLE_STD_CHRONO
//#define BOOST_ASIO_ENABLE_HANDLER_TRACKING
#include <boost/asio.hpp>
//#include <boost/asio/use_future.hpp>
using namespace boost::asio;
using namespace boost::system;
//////////////////////////////////////////
int main()
{
cout << "client start." << endl;
io_service io;
ip::udp::endpoint send_ep(
ip::address::from_string("127.0.0.1"), 6699);
ip::udp::socket sock(io);
sock.open(ip::udp::v4());
char buf[1];
sock.send_to(buffer(buf), send_ep);
vector<char> v(100,0);
ip::udp::endpoint recv_ep;
sock.receive_from(buffer(v), recv_ep);
cout << "recv from " << recv_ep.address() << " ";
cout << &v[0] << endl;
}