Revision 35, 0.8 KB
(checked in by trnewman, 16 years ago)
|
adding c++
|
Rev | Line | |
---|
[35] | 1 | // Implementation of the ClientSocket class |
---|
| 2 | |
---|
| 3 | #include "ClientSocket.h" |
---|
| 4 | #include "SocketException.h" |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | ClientSocket::ClientSocket ( std::string host, int port ) |
---|
| 8 | { |
---|
| 9 | if ( ! Socket::create() ) |
---|
| 10 | { |
---|
| 11 | throw SocketException ( "Could not create client socket." ); |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | if ( ! Socket::connect ( host, port ) ) |
---|
| 15 | { |
---|
| 16 | throw SocketException ( "Could not bind to port." ); |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | const ClientSocket& ClientSocket::operator << ( const std::string& s ) const |
---|
| 23 | { |
---|
| 24 | if ( ! Socket::send ( s ) ) |
---|
| 25 | { |
---|
| 26 | throw SocketException ( "Could not write to socket." ); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | return *this; |
---|
| 30 | |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | const ClientSocket& ClientSocket::operator >> ( std::string& s ) const |
---|
| 35 | { |
---|
| 36 | if ( ! Socket::recv ( s ) ) |
---|
| 37 | { |
---|
| 38 | throw SocketException ( "Could not read from socket." ); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | return *this; |
---|
| 42 | } |
---|