| 1 |
+ |
/* |
| 2 |
+ |
* i-scream central monitoring system |
| 3 |
+ |
* http://www.i-scream.org.uk |
| 4 |
+ |
* 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 |
|
#include "SmallNet.h" |
| 22 |
|
|
| 23 |
|
SmallNet::SmallNet(int printDebug){ |
| 26 |
|
|
| 27 |
|
if ( debug == 1 ){ |
| 28 |
|
std::cout << "SmallNet Constructor\n"; |
| 29 |
< |
} |
| 29 |
> |
} // if |
| 30 |
|
|
| 31 |
|
return; |
| 32 |
|
|
| 35 |
|
|
| 36 |
|
int SmallNet::connectHeartBeat(string host, int port){ |
| 37 |
|
|
| 18 |
– |
|
| 38 |
|
if ( debug == 1 ){ |
| 39 |
|
std::cout << "SmallNet::connectHeartBeat(" << host << "," << port << ")\n"; |
| 40 |
< |
} |
| 40 |
> |
} // if |
| 41 |
|
|
| 42 |
|
ssocket = new SubNet(host, port); |
| 43 |
|
|
| 46 |
|
} // connectHeartBeat |
| 47 |
|
|
| 48 |
|
string SmallNet::heartBeatSend(string text){ |
| 49 |
< |
|
| 31 |
< |
|
| 32 |
< |
|
| 33 |
< |
// char buf[1024]; |
| 34 |
< |
|
| 49 |
> |
|
| 50 |
|
if ( debug == 1 ){ |
| 51 |
|
std::cout << "SmallNet::heartBeatSend()\n"; |
| 52 |
< |
} |
| 52 |
> |
} // if |
| 53 |
|
|
| 54 |
|
return ssocket->sendTCP(text); |
| 55 |
|
|
| 41 |
– |
|
| 56 |
|
} // heartBeatSend |
| 57 |
|
|
| 58 |
|
|
| 60 |
|
if ( debug == 1 ){ |
| 61 |
|
std::cout << "SmallNet::closeHeartBeatConnection()\n"; |
| 62 |
|
std::cout << "Deleting socket\n"; |
| 63 |
< |
} |
| 63 |
> |
} // if |
| 64 |
|
|
| 65 |
|
// closes automatically |
| 66 |
|
delete ssocket; |
| 72 |
|
int SmallNet::connectConfig(string host, int port){ |
| 73 |
|
if ( debug == 1 ){ |
| 74 |
|
std::cout << "SmallNet::connectConfig(" << host << "," << port << ")\n"; |
| 75 |
< |
} |
| 75 |
> |
} // if |
| 76 |
|
|
| 77 |
|
return connectHeartBeat(host,port); |
| 78 |
|
|
| 81 |
|
string SmallNet::configSend(string text){ |
| 82 |
|
if ( debug == 1 ){ |
| 83 |
|
std::cout << "SmallNet::configSend()\n"; |
| 84 |
< |
} |
| 84 |
> |
} // if |
| 85 |
|
|
| 86 |
|
return heartBeatSend(text); |
| 87 |
|
|
| 90 |
|
void SmallNet::closeConfigConnection(){ |
| 91 |
|
if ( debug == 1 ){ |
| 92 |
|
std::cout << "SmallNet::closeConfigConnection()\n"; |
| 93 |
< |
} |
| 93 |
> |
} // if |
| 94 |
|
|
| 95 |
|
closeHeartBeatConnection(); |
| 96 |
|
|
| 97 |
|
return; |
| 98 |
|
|
| 99 |
< |
} |
| 99 |
> |
} // closeConfigConnection |
| 100 |
|
|
| 101 |
|
void SmallNet::sendUPDPacket( string host, int port, string message ){ |
| 102 |
|
|
| 103 |
|
if ( debug == 1 ){ |
| 104 |
|
std::cout << "SmallNet::sendUPDPacket:" << host << ":" << port << "\n"; |
| 105 |
< |
// std::cout << message << "\n"; |
| 92 |
< |
} |
| 105 |
> |
} // if |
| 106 |
|
|
| 107 |
< |
// hard coding for testing |
| 108 |
< |
/* |
| 96 |
< |
host = "raptor.ukc.ac.uk"; |
| 97 |
< |
port = 7776; |
| 98 |
< |
*/ |
| 99 |
< |
|
| 100 |
< |
ssocket = new SubNet(); |
| 101 |
< |
ssocket->sendUPDPacket(host, port, message); |
| 102 |
< |
delete ssocket; |
| 103 |
< |
|
| 104 |
< |
return; |
| 105 |
< |
} |
| 106 |
< |
|
| 107 |
< |
string SmallNet::getHostName(){ |
| 108 |
< |
|
| 109 |
< |
ssocket = new SubNet(); |
| 110 |
< |
string name = ssocket->getHostName(); |
| 107 |
> |
ssocket = new SubNet(); |
| 108 |
> |
ssocket->sendUPDPacket(host, port, message); |
| 109 |
|
delete ssocket; |
| 112 |
– |
return name; |
| 113 |
– |
} |
| 110 |
|
|
| 111 |
< |
string SmallNet::getHostIP(){ |
| 112 |
< |
|
| 117 |
< |
// (*socket).rdbuf()->bind(); |
| 118 |
< |
// return (*socket)->localaddr(); |
| 119 |
< |
return ""; |
| 120 |
< |
} |
| 111 |
> |
return; |
| 112 |
> |
} // sendUDPPacket |