blob: 863fc25084ee44bbcd83a7deae9fa8d9f12c817f (
plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// file : examples/os/net/ipv4/datagram/client.cxx
// author : Boris Kolpackov <boris@kolpackov.net>
// copyright : Copyright (c) 2005-2010 Boris Kolpackov
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
#include <cult/types.hxx>
#include <cult/os/net/ipv4/address.hxx>
#include <cult/os/net/ipv4/datagram-socket.hxx>
#include <iostream>
#include <unistd.h> // usleep
#include "protocol.hxx"
using std::cerr;
using std::endl;
using namespace Cult;
using namespace OS::Net::IPv4;
class Args {};
Int
main (Int argc, Char* argv[])
{
try
{
if (argc < 2)
throw Args ();
Address addr (argv[1], 10000);
DatagramSocket socket;
Message msg;
msg.sn = 0;
cerr << "message size : " << sizeof (msg) << " bytes" << endl;
cerr << "send buffer : " << socket.send_buffer_size () << " bytes" << endl;
for (Index i = 0; i < payload_size; i++)
{
msg.payload[i] = i;
}
for (; msg.sn < message_count; msg.sn++)
{
socket.send (&msg, sizeof (msg), addr);
// ::usleep (10);
}
return 0;
}
catch (OS::Exception const& e)
{
cerr << "errno: " << strerror (e.code ()) << endl;
}
catch (Args const&)
{
cerr << "usage: client <IPv4 address>" << endl;
}
return 1;
}
|