ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/SubNet.cpp
Revision: 1.5
Committed: Sat May 18 18:15:56 2002 UTC (22 years, 6 months ago) by tdb
Branch: MAIN
Changes since 1.4: +19 -0 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

# User Rev Content
1 tdb 1.5 /*
2     * i-scream central monitoring system
3     * Copyright (C) 2000-2002 i-scream
4     *
5     * This program is free software; you can redistribute it and/or
6     * modify it under the terms of the GNU General Public License
7     * as published by the Free Software Foundation; either version 2
8     * of the License, or (at your option) any later version.
9     *
10     * This program is distributed in the hope that it will be useful,
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     * GNU General Public License for more details.
14     *
15     * You should have received a copy of the GNU General Public License
16     * along with this program; if not, write to the Free Software
17     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18     */
19    
20 ab11 1.1 #include "SubNet.h"
21    
22 ab11 1.3 SubNet::~SubNet(){
23    
24 ab11 1.4 // free up any allocated memory
25 ab11 1.3 delete socket;
26     delete udp;
27    
28     } // ~SubNet
29    
30 ab11 1.1 SubNet::SubNet(string host, int port){
31     // constructor
32    
33 ab11 1.4 // create a pointer to the object
34 ab11 1.1 socket = new iosockinet(sockbuf::sock_stream);
35 ab11 1.4
36     // make the actual connection
37 ab11 1.1 connect = (*socket).rdbuf()->connect(host.c_str(), port);
38    
39     } // SubNet
40    
41     int SubNet::isConnected(){
42    
43     return connect;
44    
45     } // isConnected
46    
47    
48     SubNet::SubNet(){
49 ab11 1.4 // no arg constructor
50 ab11 1.1
51 ab11 1.4 // connect to any socket on the local machine with the
52     // intention of getting sys information
53 ab11 1.1 socket = new iosockinet(sockbuf::sock_stream);
54     (*socket).rdbuf()->bind();
55    
56     return;
57    
58     } // SubNet
59    
60     string SubNet::sendTCP(string text){
61    
62 ab11 1.4 int size = 1024;
63 ab11 1.3 char buf[size];
64 ab11 1.1
65     (*socket) << text.c_str() << "\n" << flush; //
66    
67 ab11 1.4 (*socket).getline(buf, size-1);
68 ab11 1.1
69     return buf;
70    
71     } // sendTCP
72    
73    
74     void SubNet::sendUPDPacket( string host, int port, string message ){
75 ab11 1.4
76     int udpSize = sizeof(message.c_str());
77 ab11 1.1
78 ab11 1.4 udp = new osockinet(sockbuf::sock_dgram);
79     (*udp)->setopt(sockbuf::so_sndbuf , &udpSize, sizeof(udpSize), sockbuf::sol_socket);
80    
81     (*udp)->connect (host.c_str(), port);
82     (*udp) << message.c_str() << flush;
83    
84     delete udp;
85 ab11 1.1
86     return;
87    
88     } // sendUPDPacket
89