ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/SubNet.cpp
Revision: 1.1
Committed: Mon Mar 5 14:02:27 2001 UTC (23 years, 8 months ago) by ab11
Branch: MAIN
Log Message:
Solves many of the problems associated with memory allocation and dealocation with the socket++ library. Also should prevent memory leaks as the proper destructor methods are being called now.

File Contents

# User Rev Content
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     char buf[1024];
32    
33     (*socket) << text.c_str() << "\n" << flush; //
34    
35     (*socket).getline (buf, 1024);
36    
37     return buf;
38    
39     } // sendTCP
40    
41    
42     void SubNet::sendUPDPacket( string host, int port, string message ){
43    
44     /*
45     host = "raptor.ukc.ac.uk";
46     port = 7776;
47     */
48    
49     int udpSize;
50     udpSize = 65536; // 8kb in bits (8192*8)
51    
52     udp = new osockinet(sockbuf::sock_dgram);
53     (*udp)->setopt(sockbuf::so_sndbuf , &udpSize, sizeof(udpSize), sockbuf::sol_socket);
54    
55     // int sndBufSize = (*udp)->sendbufsz(udpSize);
56    
57     (*udp)->connect (host.c_str(), port);
58     (*udp) << message.c_str() << endl;
59    
60     delete udp;
61    
62     return;
63    
64     } // sendUPDPacket
65    
66     string SubNet::getIPfromHost(string hostname){
67     return "";
68    
69     } // getIPFromHost
70    
71     string SubNet::getHostName(){
72    
73     string myHost = (*socket)->localhost();
74     delete socket;
75     return myHost;
76    
77    
78     } // getHostName
79    
80     string SubNet::getHostIP(){
81     return "";
82    
83     } // getHostIP