--- projects/cms/source/host/c++/SubNet.cpp 2001/03/23 14:09:57 1.3 +++ projects/cms/source/host/c++/SubNet.cpp 2002/05/21 16:47:11 1.6 @@ -1,7 +1,28 @@ +/* + * 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; @@ -10,9 +31,10 @@ SubNet::~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 @@ -25,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(); @@ -35,12 +60,12 @@ SubNet::SubNet(){ string SubNet::sendTCP(string text){ - int size = 8192; + int size = 1024; char buf[size]; (*socket) << text.c_str() << "\n" << flush; // - (*socket).getline (buf, size-1); + (*socket).getline(buf, size-1); return buf; @@ -48,37 +73,18 @@ string SubNet::sendTCP(string text){ void SubNet::sendUPDPacket( string host, int port, string message ){ - - int udpSize; - udpSize = 8129; // 8kb in bits (8192*8) - - 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; + + 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