00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "queuedConnectionManager.h"
00020 #include "queuedConnectionReader.h"
00021 #include "connectionWriter.h"
00022 #include "netAddress.h"
00023 #include "connection.h"
00024 #include "netDatagram.h"
00025
00026 #include "datagram_ui.h"
00027
00028 #include <prinrval.h>
00029
00030 int
00031 main(int argc, char *argv[]) {
00032 if (argc != 3) {
00033 nout << "test_spam_client host port\n";
00034 exit(1);
00035 }
00036
00037 string hostname = argv[1];
00038 int port = atoi(argv[2]);
00039
00040 NetAddress host;
00041 if (!host.set_host(hostname, port)) {
00042 nout << "Unknown host: " << hostname << "\n";
00043 }
00044
00045 QueuedConnectionManager cm;
00046 PT(Connection) c = cm.open_TCP_client_connection(host, 5000);
00047
00048 if (c.is_null()) {
00049 nout << "No connection.\n";
00050 exit(1);
00051 }
00052
00053 nout << "Successfully opened TCP connection to " << hostname
00054 << " on port " << port << "\n";
00055
00056 QueuedConnectionReader reader(&cm, 10);
00057 reader.add_connection(c);
00058 ConnectionWriter writer(&cm, 10);
00059
00060 bool lost_connection = false;
00061
00062 NetDatagram datagram;
00063 cout << "Enter a datagram.\n";
00064 cin >> datagram;
00065
00066 nout << "Read datagram " << datagram << "\n";
00067 datagram.dump_hex(nout);
00068 nout << "\n";
00069
00070 int num_sent = 0;
00071 int num_received = 0;
00072 PRIntervalTime last_reported_time = PR_IntervalNow();
00073 PRIntervalTime report_interval = PR_SecondsToInterval(5);
00074
00075 while (!lost_connection) {
00076
00077 if (writer.send(datagram, c, host)) {
00078 num_sent++;
00079 }
00080
00081
00082 while (cm.reset_connection_available()) {
00083 PT(Connection) connection;
00084 if (cm.get_reset_connection(connection)) {
00085 nout << "Lost connection from "
00086 << connection->get_address() << "\n";
00087 cm.close_connection(connection);
00088 if (connection == c) {
00089 lost_connection = true;
00090 }
00091 }
00092 }
00093
00094
00095 if (reader.data_available()) {
00096 NetDatagram new_datagram;
00097 if (reader.get_data(new_datagram)) {
00098 num_received++;
00099 }
00100 }
00101
00102 PRIntervalTime now = PR_IntervalNow();
00103 if ((PRIntervalTime)(now - last_reported_time) > report_interval) {
00104 nout << "Sent " << num_sent << ", received "
00105 << num_received << " datagrams.\n";
00106 last_reported_time = now;
00107 }
00108
00109
00110
00111 }
00112
00113 return (0);
00114 }
00115
00116
00117
00118
00119