Go to the documentation of this file.00001 #include <iostream>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <sys/time.h>
00005 #include <time.h>
00006
00007 #include <boost/bind.hpp>
00008 #include <boost/program_options.hpp>
00009
00010 #include "SystemConfig.h"
00011 #include "DateTime.h"
00012 #include "Exception.h"
00013 #include "NetAddress.h"
00014
00015
00016 #include "Communication.h"
00017
00018 #include "CNER.h"
00019 #include "Messages.h"
00020 #include "Types.h"
00021
00022 using namespace castor::net;
00023
00024 CastorChannel *cx;
00025 CastorChannel *sx;
00026
00027 void creceive(const char *buffer, size_t, NetAddressPtr address) {
00028 std::cout << "(C) " << buffer << " from " << *address << std::endl;
00029 }
00030
00031 void sreceive(const char *buffer, size_t, NetAddressPtr address) {
00032 std::cout << "(R) " << buffer << " from " << *address << std::endl;
00033 sx->send("Return", 7, *address);
00034 }
00035
00036 int main(int argc, char *argv[]) {
00037
00038 if (argc < 2) return 0;
00039
00040 CommunicationPtr comm = Communication::getInstance();
00041
00042 CastorChannelPtr s = comm->create(argv[1]);
00043
00044 sx = s.get();
00045
00046 if (argc == 2) {
00047 s->accept();
00048 s->callback = sreceive;
00049 } else {
00050 s->connect();
00051 s->callback = creceive;
00052 }
00053
00054 s->start();
00055
00056 comm->start(1);
00057
00058 if (argc == 2) {
00059 sleep(1000);
00060 } else {
00061
00062 for (int i = 0; i < 100; i++) {
00063 std::cout << "SEND" << std::endl;
00064 s->send("Bla", 4);
00065 sleep(1);
00066 }
00067
00068 sleep(1000);
00069 }
00070
00071 return 0;
00072 }