--- projects/cms/source/host/c++/SubNet.cpp 2001/03/06 00:39:13 1.2 +++ projects/cms/source/host/c++/SubNet.cpp 2002/05/21 16:47:11 1.6 @@ -1,11 +1,40 @@ +/* + * i-scream central monitoring system + * http://www.i-scream.org.uk + * Copyright (C) 2000-2002 i-scream + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + #include "SubNet.h" +SubNet::~SubNet(){ + + // free up any allocated memory + delete socket; + delete udp; + +} // ~SubNet + SubNet::SubNet(string host, int port){ // constructor - socket = new iosockinet(sockbuf::sock_stream); // create a pointer to the object - + socket = new iosockinet(sockbuf::sock_stream); + + // make the actual connection connect = (*socket).rdbuf()->connect(host.c_str(), port); } // SubNet @@ -18,7 +47,10 @@ int SubNet::isConnected(){ SubNet::SubNet(){ + // no arg constructor + // connect to any socket on the local machine with the + // intention of getting sys information socket = new iosockinet(sockbuf::sock_stream); (*socket).rdbuf()->bind(); @@ -29,11 +61,11 @@ SubNet::SubNet(){ string SubNet::sendTCP(string text){ int size = 1024; - char buf[size]; + char buf[size]; (*socket) << text.c_str() << "\n" << flush; // - (*socket).getline (buf, size-1); + (*socket).getline(buf, size-1); return buf; @@ -41,44 +73,18 @@ string SubNet::sendTCP(string text){ void SubNet::sendUPDPacket( string host, int port, string message ){ - - /* - host = "raptor.ukc.ac.uk"; - port = 7776; - */ - - int udpSize; - udpSize = 65536; // 8kb in bits (8192*8) - - udp = new osockinet(sockbuf::sock_dgram); - (*udp)->setopt(sockbuf::so_sndbuf , &udpSize, sizeof(udpSize), sockbuf::sol_socket); - - // int sndBufSize = (*udp)->sendbufsz(udpSize); - - (*udp)->connect (host.c_str(), port); - (*udp) << message.c_str() << flush << endl; + + int udpSize = sizeof(message.c_str()); - delete udp; + udp = new osockinet(sockbuf::sock_dgram); + (*udp)->setopt(sockbuf::so_sndbuf , &udpSize, sizeof(udpSize), sockbuf::sol_socket); + + (*udp)->connect (host.c_str(), port); + (*udp) << message.c_str() << flush; + + delete udp; return; } // sendUPDPacket -string SubNet::getIPfromHost(string hostname){ - return ""; - -} // getIPFromHost - -string SubNet::getHostName(){ - - string myHost = (*socket)->localhost(); - delete socket; - return myHost; - - -} // getHostName - -string SubNet::getHostIP(){ - return ""; - -} // getHostIP \ No newline at end of file