1 |
ab11 |
1.1 |
#include "SubNet.h" |
2 |
|
|
|
3 |
|
|
SubNet::SubNet(string host, int port){ |
4 |
|
|
// constructor |
5 |
|
|
|
6 |
|
|
socket = new iosockinet(sockbuf::sock_stream); |
7 |
|
|
// create a pointer to the object |
8 |
|
|
|
9 |
|
|
connect = (*socket).rdbuf()->connect(host.c_str(), port); |
10 |
|
|
|
11 |
|
|
} // SubNet |
12 |
|
|
|
13 |
|
|
int SubNet::isConnected(){ |
14 |
|
|
|
15 |
|
|
return connect; |
16 |
|
|
|
17 |
|
|
} // isConnected |
18 |
|
|
|
19 |
|
|
|
20 |
|
|
SubNet::SubNet(){ |
21 |
|
|
|
22 |
|
|
socket = new iosockinet(sockbuf::sock_stream); |
23 |
|
|
(*socket).rdbuf()->bind(); |
24 |
|
|
|
25 |
|
|
return; |
26 |
|
|
|
27 |
|
|
} // SubNet |
28 |
|
|
|
29 |
|
|
string SubNet::sendTCP(string text){ |
30 |
|
|
|
31 |
ab11 |
1.2 |
int size = 1024; |
32 |
|
|
char buf[size]; |
33 |
ab11 |
1.1 |
|
34 |
|
|
(*socket) << text.c_str() << "\n" << flush; // |
35 |
|
|
|
36 |
ab11 |
1.2 |
(*socket).getline (buf, size-1); |
37 |
ab11 |
1.1 |
|
38 |
|
|
return buf; |
39 |
|
|
|
40 |
|
|
} // sendTCP |
41 |
|
|
|
42 |
|
|
|
43 |
|
|
void SubNet::sendUPDPacket( string host, int port, string message ){ |
44 |
|
|
|
45 |
|
|
/* |
46 |
|
|
host = "raptor.ukc.ac.uk"; |
47 |
|
|
port = 7776; |
48 |
|
|
*/ |
49 |
|
|
|
50 |
|
|
int udpSize; |
51 |
|
|
udpSize = 65536; // 8kb in bits (8192*8) |
52 |
|
|
|
53 |
|
|
udp = new osockinet(sockbuf::sock_dgram); |
54 |
|
|
(*udp)->setopt(sockbuf::so_sndbuf , &udpSize, sizeof(udpSize), sockbuf::sol_socket); |
55 |
|
|
|
56 |
|
|
// int sndBufSize = (*udp)->sendbufsz(udpSize); |
57 |
|
|
|
58 |
|
|
(*udp)->connect (host.c_str(), port); |
59 |
ab11 |
1.2 |
(*udp) << message.c_str() << flush << endl; |
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 |