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

# Content
1 #include "SubNet.h"
2
3 SubNet::~SubNet(){
4
5 // free up any allocated memory
6 delete socket;
7 delete udp;
8
9 } // ~SubNet
10
11 SubNet::SubNet(string host, int port){
12 // constructor
13
14 // create a pointer to the object
15 socket = new iosockinet(sockbuf::sock_stream);
16
17 // make the actual connection
18 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 // no arg constructor
31
32 // connect to any socket on the local machine with the
33 // intention of getting sys information
34 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 int size = 1024;
44 char buf[size];
45
46 (*socket) << text.c_str() << "\n" << flush; //
47
48 (*socket).getline(buf, size-1);
49
50 return buf;
51
52 } // sendTCP
53
54
55 void SubNet::sendUPDPacket( string host, int port, string message ){
56
57 int udpSize = sizeof(message.c_str());
58
59 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
67 return;
68
69 } // sendUPDPacket
70