20 |
|
std::cout << "SmallNet::connectHeartBeat(" << host << "," << port << ")\n"; |
21 |
|
} |
22 |
|
|
23 |
< |
socket = new iosockinet(sockbuf::sock_stream); |
24 |
< |
// create a pointer to the object |
23 |
> |
ssocket = new SubNet(host, port); |
24 |
|
|
25 |
< |
// connect the socket |
25 |
> |
return ssocket->isConnected(); |
26 |
|
|
28 |
– |
// std::cout << socket; |
29 |
– |
|
30 |
– |
return (*socket).rdbuf()->connect(host.c_str(), port); |
31 |
– |
|
27 |
|
} // connectHeartBeat |
28 |
|
|
29 |
|
string SmallNet::heartBeatSend(string text){ |
30 |
|
|
36 |
– |
char buf[1024]; |
31 |
|
|
38 |
– |
if ( debug == 1 ){ |
39 |
– |
std::cout << "SmallNet::heartBeatSend()\n"; |
40 |
– |
} |
32 |
|
|
33 |
< |
// std::cout << socket; |
43 |
< |
// (*socket) << "BUNG BUNG BUNG" << flush; |
44 |
< |
(*socket) << text.c_str() << "\n" << flush; // |
33 |
> |
// char buf[1024]; |
34 |
|
|
35 |
|
if ( debug == 1 ){ |
36 |
< |
std::cout << "SmallNet::heartBeatSend->Sent:" << text << "\n"; |
36 |
> |
std::cout << "SmallNet::heartBeatSend()\n"; |
37 |
|
} |
38 |
|
|
39 |
+ |
return ssocket->sendTCP(text); |
40 |
|
|
41 |
< |
(*socket).getline (buf, 1024); |
52 |
< |
|
53 |
< |
return buf; |
54 |
< |
|
41 |
> |
|
42 |
|
} // heartBeatSend |
43 |
|
|
44 |
|
|
45 |
|
void SmallNet::closeHeartBeatConnection(){ |
46 |
|
if ( debug == 1 ){ |
47 |
|
std::cout << "SmallNet::closeHeartBeatConnection()\n"; |
48 |
+ |
std::cout << "Deleting socket\n"; |
49 |
|
} |
50 |
|
|
51 |
|
// closes automatically |
52 |
< |
// socket.close(); |
52 |
> |
delete ssocket; |
53 |
|
return; |
54 |
|
|
55 |
|
} // closeHeartBeatConnection |
88 |
|
|
89 |
|
if ( debug == 1 ){ |
90 |
|
std::cout << "SmallNet::sendUPDPacket:" << host << ":" << port << "\n"; |
91 |
< |
std::cout << message << "\n"; |
91 |
> |
// std::cout << message << "\n"; |
92 |
|
} |
93 |
|
|
94 |
< |
osockinet udpSocket(sockbuf::sock_dgram); |
95 |
< |
int udpSize; |
96 |
< |
udpSize = 8192; |
97 |
< |
udpSocket->setopt(sockbuf::so_sndbuf , &udpSize, sizeof(udpSize), sockbuf::sol_socket); |
98 |
< |
udpSocket->connect (host.c_str(), port); |
99 |
< |
udpSocket << message.c_str() << endl; |
94 |
> |
// 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 |
|
|
104 |
|
return; |
105 |
+ |
} |
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 |
|
} |