ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/SubNet.cpp
Revision: 1.4
Committed: Tue Mar 27 00:04:55 2001 UTC (23 years, 8 months ago) by ab11
Branch: MAIN
CVS Tags: PROJECT_COMPLETION
Changes since 1.3: +18 -32 lines
Log Message:
tidied up

File Contents

# User Rev Content
1 ab11 1.1 #include "SubNet.h"
2    
3 ab11 1.3 SubNet::~SubNet(){
4    
5 ab11 1.4 // free up any allocated memory
6 ab11 1.3 delete socket;
7     delete udp;
8    
9     } // ~SubNet
10    
11 ab11 1.1 SubNet::SubNet(string host, int port){
12     // constructor
13    
14 ab11 1.4 // create a pointer to the object
15 ab11 1.1 socket = new iosockinet(sockbuf::sock_stream);
16 ab11 1.4
17     // make the actual connection
18 ab11 1.1 connect = (*socket).rdbuf()->connect(host.c_str(), port);
19    
20     } // SubNet
21    
22     int SubNet::isConnected(){
23    
24     return connect;
25    
26     } // isConnected
27    
28    
29     SubNet::SubNet(){
30 ab11 1.4 // no arg constructor
31 ab11 1.1
32 ab11 1.4 // connect to any socket on the local machine with the
33     // intention of getting sys information
34 ab11 1.1 socket = new iosockinet(sockbuf::sock_stream);
35     (*socket).rdbuf()->bind();
36    
37     return;
38    
39     } // SubNet
40    
41     string SubNet::sendTCP(string text){
42    
43 ab11 1.4 int size = 1024;
44 ab11 1.3 char buf[size];
45 ab11 1.1
46     (*socket) << text.c_str() << "\n" << flush; //
47    
48 ab11 1.4 (*socket).getline(buf, size-1);
49 ab11 1.1
50     return buf;
51    
52     } // sendTCP
53    
54    
55     void SubNet::sendUPDPacket( string host, int port, string message ){
56 ab11 1.4
57     int udpSize = sizeof(message.c_str());
58 ab11 1.1
59 ab11 1.4 udp = new osockinet(sockbuf::sock_dgram);
60     (*udp)->setopt(sockbuf::so_sndbuf , &udpSize, sizeof(udpSize), sockbuf::sol_socket);
61    
62     (*udp)->connect (host.c_str(), port);
63     (*udp) << message.c_str() << flush;
64    
65     delete udp;
66 ab11 1.1
67     return;
68    
69     } // sendUPDPacket
70