--- projects/cms/source/host/c++/SmallNet.cpp 2001/02/26 14:42:43 1.2 +++ projects/cms/source/host/c++/SmallNet.cpp 2001/02/26 14:55:51 1.3 @@ -1,48 +1,114 @@ #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 + socket = new iosockinet(sockbuf::sock_stream); + // create a pointer to the object + + // connect the socket + + // std::cout << socket; + + return (*socket).rdbuf()->connect(host.c_str(), port); + +} // connectHeartBeat - string SmallNet::heartBeatSend(string text){ + char buf[1024]; - return ""; + if ( debug == 1 ){ + std::cout << "SmallNet::heartBeatSend()\n"; + } -}; // heartBeatSend + // std::cout << socket; + // (*socket) << "BUNG BUNG BUNG" << flush; + (*socket) << text.c_str() << "\n" << flush; // + + if ( debug == 1 ){ + std::cout << "SmallNet::heartBeatSend->Sent:" << text << "\n"; + } + + + (*socket).getline (buf, 1024); + + return buf; + +} // heartBeatSend void SmallNet::closeHeartBeatConnection(){ + if ( debug == 1 ){ + std::cout << "SmallNet::closeHeartBeatConnection()\n"; + } - + // closes automatically + // socket.close(); 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"; + } + + osockinet udpSocket(sockbuf::sock_dgram); + int udpSize; + udpSize = 8192; + udpSocket->setopt(sockbuf::so_sndbuf , &udpSize, sizeof(udpSize), sockbuf::sol_socket); + udpSocket->connect (host.c_str(), port); + udpSocket << message.c_str() << endl; + + return; +} \ No newline at end of file