IT++ Logo
tcp_client_server.h
Go to the documentation of this file.
1
28#ifndef TCP_CLIENT_SERVER_H
29#define TCP_CLIENT_SERVER_H
30
31#include <itpp/itexports.h>
32
33#if (defined(_MSC_VER) && defined(ITPP_SHARED_LIB) && !defined(itpp_EXPORTS))
34
35#ifndef ITPP_PROTOCOL_EXCLUDED
36#define ITPP_PROTOCOL_EXCLUDED
37#pragma message( "PROTOCOL definitions are not available for MSVC shared builds" )
38#endif
39
40#else
41
42#include <itpp/protocol/tcp.h>
43
44
45namespace itpp
46{
47
49
50
55{
56public:
59 write.set_name("TcpServerApplicationWriteSignal");
61 }
64
67
69 void write_to_net(unsigned byte_size, double delta_time) {
70 itpp::Packet *packet = new Packet(8*byte_size);
71 write(packet, delta_time);
72
73 std::cout << "TcpServerApplication::write_to_net,"
74 << " byte_size=" << packet->bit_size() / 8
75 << " ptr=" << packet
76 << " time=" << Event_Queue::now() << std::endl;
77 }
78};
79
84{
85public:
88 tcp_receiver_p = tcp_recv_p;
89 tcp_sender_p = tcp_snd_p;
90 nbr_bytes_received = 0;
91 select.forward(this, &TCP_Client_Application::received_packet_indication);
92 select.set_name("TcpClientApplicationSelectSlot");
93 seq_num_index = 0;
94 }
95
98
101
103 void read_from_net(unsigned byte_size) {
104 nbr_bytes_to_receive = byte_size;
105 seq_num_val.set_size(10 + byte_size / 1460);
106 seq_num_val.zeros();
107 seq_num_time.set_size(10 + byte_size / 1460);
108 seq_num_time.zeros();
109 seq_num_val(0) = 0;
110 seq_num_time(0) = 0;
111 seq_num_index = 1;
112 };
113
114private:
115 TCP_Receiver *tcp_receiver_p;
116 TCP_Sender *tcp_sender_p;
117 unsigned nbr_bytes_received;
118 unsigned nbr_bytes_to_receive;
119
120 vec seq_num_val;
121 vec seq_num_time;
122 int seq_num_index;
123
124 void TCP_Client_Application::received_packet_indication(int label) {
125
126 itpp::Packet &packet = tcp_receiver_p->get_user_message();
127 nbr_bytes_received = nbr_bytes_received + packet.bit_size() / 8;
128 delete &packet;
129
130 if (seq_num_index >= seq_num_time.size()) {
131 seq_num_time.set_size(2*seq_num_time.size(), true);
132 seq_num_val.set_size(2*seq_num_val.size(), true);
133 }
134
135 seq_num_val(seq_num_index) = nbr_bytes_received;
136 seq_num_time(seq_num_index) = Event_Queue::now();
137 seq_num_index++;
138
139 std::cout << "### sequence number: " << nbr_bytes_received
140 << " ### time:" << Event_Queue::now() << std::endl;
141
142 if (nbr_bytes_received >= nbr_bytes_to_receive) {
143 std::cout << "###### Stop sender and receiver" << std::endl;
144 tcp_receiver_p->release();
145 tcp_sender_p->release();
146 tcp_sender_p->save_trace("seq_num.it");
147 seq_num_val.set_size(seq_num_index, true);
148 seq_num_time.set_size(seq_num_index, true);
149 save_to_file("seq_num.it");
150 }
151 }
152
153 void TCP_Client_Application::save_to_file(string file) {
154
155 it_file ff2(file);
156 ff2 << Name("seq_num_val") << seq_num_val;
157 ff2 << Name("seq_num_time") << seq_num_time;
158 ff2 << Name("seq_num_index") << seq_num_index;
159 ff2.flush();
160 ff2.close();
161 }
162
163};
164
166
167} // namespace itpp
168
169#endif
170
171#endif //TCP_CLIENT_SERVER_H
static Ttype now()
Return current time.
Definition events.h:139
int bit_size()
get size of packet in bits
Definition packet.h:67
Signals and slots.
void set_name(const std::string &signal_name)
set name of signal
void set_debug(const bool enable_debug=true)
Set debug mode. If true all signals are printed to stdout.
Slot Class.
Slot< TCP_Client_Application, int > select
ADD DOCUMENTATION HERE.
void read_from_net(unsigned byte_size)
ADD DOCUMENTATION HERE.
TCP_Client_Application(TCP_Sender *tcp_snd_p, TCP_Receiver *tcp_recv_p)
Default constructor.
virtual void release(std::string trace_filename="")
ADD DOCUMENTATION HERE.
itpp::Packet & get_user_message()
called by higher layer
virtual void release(std::string trace_filename="")
ADD DOCUMENTATION HERE.
virtual void save_trace(std::string filename)
ADD DOCUMENTATION HERE.
void write_to_net(unsigned byte_size, double delta_time)
ADD DOCUMENTATION HERE.
TCP_Server_Application()
Default constructor.
Signal< itpp::Packet * > write
ADD DOCUMENTATION HERE.
itpp namespace
Definition itmex.h:37
Definition of Transport Control Protocol (TCP)
SourceForge Logo

Generated on Tue Dec 10 2024 04:49:37 for IT++ by Doxygen 1.12.0