--- projects/cms/source/host/c++/SmallNet.cpp 2001/01/24 19:33:13 1.1 +++ projects/cms/source/host/c++/SmallNet.cpp 2001/03/05 12:39:43 1.4 @@ -1,48 +1,120 @@ #include "SmallNet.h" -SmallNet::SmallNet(){ +SmallNet::SmallNet(int printDebug){ + debug = printDebug; + + if ( debug == 1 ){ + std::cout << "SmallNet Constructor\n"; + } + return; -}; // SmallNet +} // SmallNet int SmallNet::connectHeartBeat(string host, int port){ - return 0; + if ( debug == 1 ){ + std::cout << "SmallNet::connectHeartBeat(" << host << "," << port << ")\n"; + } -}; // connectHeartBeat + ssocket = new SubNet(host, port); + + return ssocket->isConnected(); + +} // connectHeartBeat - string SmallNet::heartBeatSend(string text){ - return ""; -}; // heartBeatSend + // char buf[1024]; + + if ( debug == 1 ){ + std::cout << "SmallNet::heartBeatSend()\n"; + } + + return ssocket->sendTCP(text); + +} // heartBeatSend + void SmallNet::closeHeartBeatConnection(){ + if ( debug == 1 ){ + std::cout << "SmallNet::closeHeartBeatConnection()\n"; + std::cout << "Deleting socket\n"; + } - + // closes automatically + delete ssocket; return; -}; // closeHeartBeatConnection +} // closeHeartBeatConnection -int SmallNet::connectConfig(){ +int SmallNet::connectConfig(string host, int port){ + if ( debug == 1 ){ + std::cout << "SmallNet::connectConfig(" << host << "," << port << ")\n"; + } + return connectHeartBeat(host,port); - return 0; - -}; // makeConfigConnection +} // makeConfigConnection string SmallNet::configSend(string text){ + if ( debug == 1 ){ + std::cout << "SmallNet::configSend()\n"; + } + + return heartBeatSend(text); +} // configSend + +void SmallNet::closeConfigConnection(){ + if ( debug == 1 ){ + std::cout << "SmallNet::closeConfigConnection()\n"; + } + closeHeartBeatConnection(); - return ""; + return; -}; // configSend +} +void SmallNet::sendUPDPacket( string host, int port, string message ){ + + if ( debug == 1 ){ + std::cout << "SmallNet::sendUPDPacket:" << host << ":" << port << "\n"; + // std::cout << message << "\n"; + } + + // hard coding for testing + /* + host = "raptor.ukc.ac.uk"; + port = 7776; + */ + + ssocket = new SubNet(); + ssocket->sendUPDPacket(host, port, message); + delete ssocket; + + return; +} + +string SmallNet::getHostName(){ + + ssocket = new SubNet(); + string name = ssocket->getHostName(); + delete ssocket; + return name; +} + +string SmallNet::getHostIP(){ + + // (*socket).rdbuf()->bind(); + // return (*socket)->localaddr(); + return ""; +} \ No newline at end of file