| 6 |
|
|
| 7 |
|
if ( debug == 1 ){ |
| 8 |
|
std::cout << "SmallNet Constructor\n"; |
| 9 |
< |
} |
| 9 |
> |
} // if |
| 10 |
|
|
| 11 |
|
return; |
| 12 |
|
|
| 15 |
|
|
| 16 |
|
int SmallNet::connectHeartBeat(string host, int port){ |
| 17 |
|
|
| 18 |
– |
|
| 18 |
|
if ( debug == 1 ){ |
| 19 |
|
std::cout << "SmallNet::connectHeartBeat(" << host << "," << port << ")\n"; |
| 20 |
< |
} |
| 20 |
> |
} // if |
| 21 |
|
|
| 22 |
< |
socket = new iosockinet(sockbuf::sock_stream); |
| 24 |
< |
// create a pointer to the object |
| 22 |
> |
ssocket = new SubNet(host, port); |
| 23 |
|
|
| 24 |
< |
// connect the socket |
| 24 |
> |
return ssocket->isConnected(); |
| 25 |
|
|
| 28 |
– |
// std::cout << socket; |
| 29 |
– |
|
| 30 |
– |
return (*socket).rdbuf()->connect(host.c_str(), port); |
| 31 |
– |
|
| 26 |
|
} // connectHeartBeat |
| 27 |
|
|
| 28 |
|
string SmallNet::heartBeatSend(string text){ |
| 29 |
< |
|
| 36 |
< |
char buf[1024]; |
| 37 |
< |
|
| 29 |
> |
|
| 30 |
|
if ( debug == 1 ){ |
| 31 |
|
std::cout << "SmallNet::heartBeatSend()\n"; |
| 32 |
< |
} |
| 32 |
> |
} // if |
| 33 |
|
|
| 34 |
< |
// std::cout << socket; |
| 43 |
< |
// (*socket) << "BUNG BUNG BUNG" << flush; |
| 44 |
< |
(*socket) << text.c_str() << "\n" << flush; // |
| 34 |
> |
return ssocket->sendTCP(text); |
| 35 |
|
|
| 46 |
– |
if ( debug == 1 ){ |
| 47 |
– |
std::cout << "SmallNet::heartBeatSend->Sent:" << text << "\n"; |
| 48 |
– |
} |
| 49 |
– |
|
| 50 |
– |
|
| 51 |
– |
(*socket).getline (buf, 1024); |
| 52 |
– |
|
| 53 |
– |
return buf; |
| 54 |
– |
|
| 36 |
|
} // heartBeatSend |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
void SmallNet::closeHeartBeatConnection(){ |
| 40 |
|
if ( debug == 1 ){ |
| 41 |
|
std::cout << "SmallNet::closeHeartBeatConnection()\n"; |
| 42 |
< |
} |
| 42 |
> |
std::cout << "Deleting socket\n"; |
| 43 |
> |
} // if |
| 44 |
|
|
| 45 |
|
// closes automatically |
| 46 |
< |
// socket.close(); |
| 46 |
> |
delete ssocket; |
| 47 |
|
return; |
| 48 |
|
|
| 49 |
|
} // closeHeartBeatConnection |
| 52 |
|
int SmallNet::connectConfig(string host, int port){ |
| 53 |
|
if ( debug == 1 ){ |
| 54 |
|
std::cout << "SmallNet::connectConfig(" << host << "," << port << ")\n"; |
| 55 |
< |
} |
| 55 |
> |
} // if |
| 56 |
|
|
| 57 |
|
return connectHeartBeat(host,port); |
| 58 |
|
|
| 61 |
|
string SmallNet::configSend(string text){ |
| 62 |
|
if ( debug == 1 ){ |
| 63 |
|
std::cout << "SmallNet::configSend()\n"; |
| 64 |
< |
} |
| 64 |
> |
} // if |
| 65 |
|
|
| 66 |
|
return heartBeatSend(text); |
| 67 |
|
|
| 70 |
|
void SmallNet::closeConfigConnection(){ |
| 71 |
|
if ( debug == 1 ){ |
| 72 |
|
std::cout << "SmallNet::closeConfigConnection()\n"; |
| 73 |
< |
} |
| 73 |
> |
} // if |
| 74 |
|
|
| 75 |
|
closeHeartBeatConnection(); |
| 76 |
|
|
| 77 |
|
return; |
| 78 |
|
|
| 79 |
< |
} |
| 79 |
> |
} // closeConfigConnection |
| 80 |
|
|
| 81 |
|
void SmallNet::sendUPDPacket( string host, int port, string message ){ |
| 82 |
|
|
| 83 |
|
if ( debug == 1 ){ |
| 84 |
|
std::cout << "SmallNet::sendUPDPacket:" << host << ":" << port << "\n"; |
| 85 |
< |
std::cout << message << "\n"; |
| 104 |
< |
} |
| 85 |
> |
} // if |
| 86 |
|
|
| 87 |
< |
osockinet udpSocket(sockbuf::sock_dgram); |
| 88 |
< |
int udpSize; |
| 89 |
< |
udpSize = 8192; |
| 90 |
< |
udpSocket->setopt(sockbuf::so_sndbuf , &udpSize, sizeof(udpSize), sockbuf::sol_socket); |
| 110 |
< |
udpSocket->connect (host.c_str(), port); |
| 111 |
< |
udpSocket << message.c_str() << endl; |
| 112 |
< |
|
| 87 |
> |
ssocket = new SubNet(); |
| 88 |
> |
ssocket->sendUPDPacket(host, port, message); |
| 89 |
> |
delete ssocket; |
| 90 |
> |
|
| 91 |
|
return; |
| 92 |
< |
} |
| 92 |
> |
} // sendUDPPacket |