working example server and client
[anytun.git] / syncSocket.cpp
blob96da70cc0253f703695073ac72c469410ab6da78
1 #include <sstream>
2 #include <iostream>
3 #include <string>
4 #include "routingTable.h"
5 #include "rtpSessionTable.h"
6 #include <boost/archive/text_oarchive.hpp>
7 #include <boost/archive/text_iarchive.hpp>
10 //#include "connectionParam.h"
11 #include "Sockets/Utility.h"
12 #include "syncSocket.h"
13 #include "syncCommand.h"
14 #include "buffer.h"
15 //#include "log.h"
17 SyncSocket::SyncSocket(ISocketHandler& h,ConnectionList & cl)
18 :TcpSocket(h),cl_(cl)
20 SetConnectTimeout(12);
25 void SyncSocket::OnAccept()
27 // Send( Utility::GetLocalHostname() + "\n");
28 // Send( Utility::GetLocalAddress() + "\n");
29 // Send("Number of sockets in list : " + Utility::l2string(Handler().GetCount()) + "\n");
30 // Send("\n");
31 //TODO Locking here
32 ConnectionMap::iterator cit = cl_.getBeginUnlocked();
33 for (;cit!=cl_.getEndUnlocked();++cit)
35 std::ostringstream sout;
36 boost::archive::text_oarchive oa(sout);
37 const SyncCommand scom(cl_,cit->first);
38 oa << scom;
39 std::stringstream lengthout;
40 lengthout << std::setw(5) << std::setfill('0') << sout.str().size()<< ' ';
41 Send(lengthout.str());
42 Send(sout.str());
44 //TODO Locking here
45 RoutingMap::iterator it = gRoutingTable.getBeginUnlocked();
46 for (;it!=gRoutingTable.getEndUnlocked();++it)
48 NetworkPrefix tmp(it->first);
49 std::ostringstream sout;
50 boost::archive::text_oarchive oa(sout);
51 const SyncCommand scom(tmp);
52 oa << scom;
53 std::stringstream lengthout;
54 lengthout << std::setw(5) << std::setfill('0') << sout.str().size()<< ' ';
55 Send(lengthout.str());
56 Send(sout.str());
58 //TODO Locking here
59 RtpSessionMap::iterator rit = gRtpSessionTable.getBeginUnlocked();
60 for (;rit!=gRtpSessionTable.getEndUnlocked();++rit)
62 std::ostringstream sout;
63 boost::archive::text_oarchive oa(sout);
64 const SyncCommand scom(rit->first);
65 oa << scom;
66 std::stringstream lengthout;
67 lengthout << std::setw(5) << std::setfill('0') << sout.str().size()<< ' ';
68 Send(lengthout.str());
69 Send(sout.str());
73 //void StatusSocket::InitSSLServer()
74 //{
75 // InitializeContext("server.pem", "keypwd", SSLv23_method());
76 //}
79 //void StatusSocket::Init()
80 //{
81 // EnableSSL();
82 //}