1 |
ab11 |
1.1 |
#include "SubNet.h" |
2 |
|
|
|
3 |
ab11 |
1.3 |
SubNet::~SubNet(){ |
4 |
|
|
|
5 |
|
|
delete socket; |
6 |
|
|
delete udp; |
7 |
|
|
|
8 |
|
|
} // ~SubNet |
9 |
|
|
|
10 |
ab11 |
1.1 |
SubNet::SubNet(string host, int port){ |
11 |
|
|
// constructor |
12 |
|
|
|
13 |
|
|
socket = new iosockinet(sockbuf::sock_stream); |
14 |
|
|
// create a pointer to the object |
15 |
|
|
|
16 |
|
|
connect = (*socket).rdbuf()->connect(host.c_str(), port); |
17 |
|
|
|
18 |
|
|
} // SubNet |
19 |
|
|
|
20 |
|
|
int SubNet::isConnected(){ |
21 |
|
|
|
22 |
|
|
return connect; |
23 |
|
|
|
24 |
|
|
} // isConnected |
25 |
|
|
|
26 |
|
|
|
27 |
|
|
SubNet::SubNet(){ |
28 |
|
|
|
29 |
|
|
socket = new iosockinet(sockbuf::sock_stream); |
30 |
|
|
(*socket).rdbuf()->bind(); |
31 |
|
|
|
32 |
|
|
return; |
33 |
|
|
|
34 |
|
|
} // SubNet |
35 |
|
|
|
36 |
|
|
string SubNet::sendTCP(string text){ |
37 |
|
|
|
38 |
ab11 |
1.3 |
int size = 8192; |
39 |
|
|
char buf[size]; |
40 |
ab11 |
1.1 |
|
41 |
|
|
(*socket) << text.c_str() << "\n" << flush; // |
42 |
|
|
|
43 |
ab11 |
1.2 |
(*socket).getline (buf, size-1); |
44 |
ab11 |
1.1 |
|
45 |
|
|
return buf; |
46 |
|
|
|
47 |
|
|
} // sendTCP |
48 |
|
|
|
49 |
|
|
|
50 |
|
|
void SubNet::sendUPDPacket( string host, int port, string message ){ |
51 |
|
|
|
52 |
ab11 |
1.3 |
int udpSize; |
53 |
|
|
udpSize = 8129; // 8kb in bits (8192*8) |
54 |
ab11 |
1.1 |
|
55 |
|
|
udp = new osockinet(sockbuf::sock_dgram); |
56 |
|
|
(*udp)->setopt(sockbuf::so_sndbuf , &udpSize, sizeof(udpSize), sockbuf::sol_socket); |
57 |
|
|
|
58 |
ab11 |
1.3 |
(*udp)->connect (host.c_str(), port); |
59 |
|
|
(*udp) << message.c_str() << flush; |
60 |
ab11 |
1.1 |
|
61 |
|
|
delete udp; |
62 |
|
|
|
63 |
|
|
return; |
64 |
|
|
|
65 |
|
|
} // sendUPDPacket |
66 |
|
|
|
67 |
|
|
string SubNet::getIPfromHost(string hostname){ |
68 |
|
|
return ""; |
69 |
|
|
|
70 |
|
|
} // getIPFromHost |
71 |
|
|
|
72 |
|
|
string SubNet::getHostName(){ |
73 |
|
|
|
74 |
|
|
string myHost = (*socket)->localhost(); |
75 |
|
|
delete socket; |
76 |
|
|
return myHost; |
77 |
|
|
|
78 |
|
|
|
79 |
|
|
} // getHostName |
80 |
|
|
|
81 |
|
|
string SubNet::getHostIP(){ |
82 |
|
|
return ""; |
83 |
|
|
|
84 |
|
|
} // getHostIP |