forked from lizhenghn123/CppLanguagePrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActiveSocket.cpp
More file actions
42 lines (33 loc) · 829 Bytes
/
ActiveSocket.cpp
File metadata and controls
42 lines (33 loc) · 829 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
#include "net/ActiveSocket.h"
NAMESPACE_ZL_NET_START
ActiveSocket::ActiveSocket(ZL_SOCKET fd) : Socket(fd)
{
}
ActiveSocket::ActiveSocket(const char *host, int port) : Socket(SocketUtil::createSocket())
{
if(!Socket::connect(host, port))
{
throw SocketException("Could not Connect to server.");
}
}
ActiveSocket::~ActiveSocket()
{
}
const ActiveSocket& ActiveSocket::operator << (const std::string& data) const
{
if(!Socket::send(data))
{
throw SocketException("Could not write to socket.");
}
return *this;
}
const ActiveSocket& ActiveSocket::operator >> (std::string& data) const
{
if(!Socket::recv(data))
{
throw SocketException("Could not read from socket.");
//printf("Could not read from socket.");
}
return *this;
}
NAMESPACE_ZL_NET_END