#ifndef SOCK_CLIENTSOCKET_H
#define SOCK_CLIENTSOCKET_H
// #include <standard library headers>
// #include <other library headers>
// #include "customer headers"
#include "Socket.h"
namespace sock
{
class ClientSocket : public Socket
{
public:
ClientSocket(const std::string& host, int port)
{
if (!Socket::Create())
{
throw SocketException("Could not create client socket.");
}
if (!Socket::Connect(host, port))
{
throw SocketException("Could not connect to server.");
}
}
virtual ~ClientSocket() {}
public:
const ClientSocket& operator << (const std::string& s) const
{
if (!Socket::Send(s))
{
throw SocketException("Could not write to socket.");
}
return *this;
}
const ClientSocket& operator >> (std::string& s) const
{
if (Socket::Recv(s) < 0)
{
throw SocketException("Could not read from socket.");
}
return *this;
}
};
}
#endif // SOCK_CLIENTSOCKET_H
Socket封装5
最新推荐文章于 2012-03-26 10:07:27 发布