-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientSocket.cpp
More file actions
42 lines (30 loc) · 790 Bytes
/
ClientSocket.cpp
File metadata and controls
42 lines (30 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Implementation of the ClientSocket class
#include "ClientSocket.h"
#include "SocketException.h"
ClientSocket::ClientSocket ( std::string host, int port )
{
if ( ! Socket::create() )
{
throw SocketException ( "Could not create client socket." );
}
if ( ! Socket::connect ( host, port ) )
{
throw SocketException ( "Could not bind to port." );
}
}
const ClientSocket& ClientSocket::operator << ( const std::string& s ) const
{
if ( ! Socket::send ( s ) )
{
throw SocketException ( "Could not write to socket." );
}
return *this;
}
const ClientSocket& ClientSocket::operator >> ( std::string& s ) const
{
if ( ! Socket::recv ( s ) )
{
throw SocketException ( "Could not read from socket." );
}
return *this;
}