53 lines
1.5 KiB
C++
53 lines
1.5 KiB
C++
#ifndef CLIENT_SOCKET_H
|
|
#define CLIENT_SOCKET_H
|
|
|
|
#include "CCSocket.h"
|
|
#include "../base/CCByteArray.h"
|
|
|
|
namespace CTL {
|
|
class SocketInputStream {
|
|
Socket* socket;
|
|
public:
|
|
explicit SocketInputStream(Socket* sock);
|
|
int read(char* buffer, size_t length) const;
|
|
int read() const;
|
|
int read(ByteArray& buffer, size_t length) const;
|
|
bool available() const;
|
|
};
|
|
class SocketOutputStream {
|
|
Socket* socket;
|
|
public:
|
|
explicit SocketOutputStream(Socket* sock);
|
|
int write(const void* buffer, size_t length) const;
|
|
bool write(ByteArray& buffer) const;
|
|
bool write(const std::string& str) const;
|
|
};
|
|
class ClientSocket {
|
|
Socket* socket;
|
|
SocketInputStream* inputStream;
|
|
SocketOutputStream* outputStream;
|
|
IPVX IP_x;
|
|
std::string hostAddress;
|
|
bool isClosed_t, isConnect_t;
|
|
int Port;
|
|
public:
|
|
private:
|
|
public:
|
|
ClientSocket();
|
|
~ClientSocket();
|
|
ClientSocket(const InetAddress& address,int Port);
|
|
explicit ClientSocket(Socket* sock);
|
|
bool connect(const InetAddress& address,int Port);
|
|
void close();
|
|
bool isConnect() const;
|
|
bool isClosed() const;
|
|
SocketInputStream* getInputStream() const;
|
|
SocketOutputStream* getOutputStream() const;
|
|
Socket* getSocket() const;
|
|
int getPort() const;
|
|
InetAddress getHostAddress() const;
|
|
};
|
|
}
|
|
|
|
#endif
|