ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/SmallNet.cpp
Revision: 1.4
Committed: Mon Mar 5 12:39:43 2001 UTC (23 years, 6 months ago) by ab11
Branch: MAIN
Changes since 1.3: +33 -27 lines
Log Message:
Modified networking conponents to support subclass of SubNet, No more core dump errors! (probably) also implemented Host Heartbeat Connections

File Contents

# User Rev Content
1 ab11 1.1 #include "SmallNet.h"
2    
3 ab11 1.3 SmallNet::SmallNet(int printDebug){
4    
5     debug = printDebug;
6    
7     if ( debug == 1 ){
8     std::cout << "SmallNet Constructor\n";
9     }
10 ab11 1.1
11     return;
12    
13 ab11 1.3 } // SmallNet
14 ab11 1.1
15    
16     int SmallNet::connectHeartBeat(string host, int port){
17    
18    
19 ab11 1.3 if ( debug == 1 ){
20     std::cout << "SmallNet::connectHeartBeat(" << host << "," << port << ")\n";
21     }
22    
23 ab11 1.4 ssocket = new SubNet(host, port);
24 ab11 1.3
25 ab11 1.4 return ssocket->isConnected();
26 ab11 1.3
27     } // connectHeartBeat
28 ab11 1.1
29     string SmallNet::heartBeatSend(string text){
30    
31 ab11 1.3
32    
33 ab11 1.4 // char buf[1024];
34 ab11 1.3
35     if ( debug == 1 ){
36 ab11 1.4 std::cout << "SmallNet::heartBeatSend()\n";
37 ab11 1.3 }
38 ab11 1.1
39 ab11 1.4 return ssocket->sendTCP(text);
40 ab11 1.1
41 ab11 1.4
42 ab11 1.3 } // heartBeatSend
43 ab11 1.1
44    
45     void SmallNet::closeHeartBeatConnection(){
46 ab11 1.3 if ( debug == 1 ){
47     std::cout << "SmallNet::closeHeartBeatConnection()\n";
48 ab11 1.4 std::cout << "Deleting socket\n";
49 ab11 1.3 }
50 ab11 1.1
51 ab11 1.3 // closes automatically
52 ab11 1.4 delete ssocket;
53 ab11 1.1 return;
54    
55 ab11 1.3 } // closeHeartBeatConnection
56 ab11 1.1
57    
58 ab11 1.3 int SmallNet::connectConfig(string host, int port){
59     if ( debug == 1 ){
60     std::cout << "SmallNet::connectConfig(" << host << "," << port << ")\n";
61     }
62 ab11 1.1
63 ab11 1.3 return connectHeartBeat(host,port);
64 ab11 1.1
65 ab11 1.3 } // makeConfigConnection
66 ab11 1.1
67     string SmallNet::configSend(string text){
68 ab11 1.3 if ( debug == 1 ){
69     std::cout << "SmallNet::configSend()\n";
70     }
71    
72     return heartBeatSend(text);
73    
74     } // configSend
75    
76     void SmallNet::closeConfigConnection(){
77     if ( debug == 1 ){
78     std::cout << "SmallNet::closeConfigConnection()\n";
79     }
80    
81     closeHeartBeatConnection();
82    
83     return;
84    
85     }
86    
87     void SmallNet::sendUPDPacket( string host, int port, string message ){
88    
89     if ( debug == 1 ){
90     std::cout << "SmallNet::sendUPDPacket:" << host << ":" << port << "\n";
91 ab11 1.4 // std::cout << message << "\n";
92 ab11 1.3 }
93    
94 ab11 1.4 // hard coding for testing
95     /*
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 ab11 1.3
104     return;
105 ab11 1.4 }
106    
107     string SmallNet::getHostName(){
108    
109     ssocket = new SubNet();
110     string name = ssocket->getHostName();
111     delete ssocket;
112     return name;
113     }
114    
115     string SmallNet::getHostIP(){
116    
117     // (*socket).rdbuf()->bind();
118     // return (*socket)->localaddr();
119     return "";
120 ab11 1.3 }