ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/SubNet.cpp
Revision: 1.6
Committed: Tue May 21 16:47:11 2002 UTC (22 years, 4 months ago) by tdb
Branch: MAIN
Changes since 1.5: +1 -0 lines
Log Message:
Added URL to GPL headers.

File Contents

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