A class that encapsulates a socket client to be used for network communication.
More...
#include <SocketClient.h>
A class that encapsulates a socket client to be used for network communication.
exploringBB::SocketClient::SocketClient |
( |
std::string |
serverName, |
|
|
int |
portNumber |
|
) |
| |
36 this->serverName = serverName;
37 this->portNumber = portNumber;
38 this->isConnected =
false;
exploringBB::SocketClient::~SocketClient |
( |
| ) |
|
|
virtual |
112 if (this->isConnected ==
true){
virtual int disconnectFromServer()
Definition: SocketClient.cpp:105
int exploringBB::SocketClient::connectToServer |
( |
| ) |
|
|
virtual |
43 socketfd = socket(AF_INET, SOCK_STREAM, 0);
45 perror(
"Socket Client: error opening socket.\n");
48 server = gethostbyname(serverName.data());
50 perror(
"Socket Client: error - no such host.\n");
53 bzero((
char *) &serverAddress,
sizeof(serverAddress));
54 serverAddress.sin_family = AF_INET;
55 bcopy((
char *)server->h_addr,(
char *)&serverAddress.sin_addr.s_addr, server->h_length);
56 serverAddress.sin_port = htons(portNumber);
58 if (connect(socketfd, (
struct sockaddr *) &serverAddress,
sizeof(serverAddress)) < 0){
59 perror(
"Socket Client: error connecting to the server.\n");
62 this->isConnected =
true;
int exploringBB::SocketClient::disconnectFromServer |
( |
| ) |
|
|
virtual |
106 this->isConnected =
false;
107 close(this->socketfd);
bool exploringBB::SocketClient::isClientConnected |
( |
| ) |
|
|
inline |
57 {
return this->isConnected; }
string exploringBB::SocketClient::receive |
( |
int |
size = 1024 | ) |
|
|
virtual |
78 char readBuffer[size];
79 int n =
read(this->socketfd, readBuffer,
sizeof(readBuffer));
81 perror(
"Socket Client: error reading from socket");
83 return string(readBuffer);
string read(string path, string filename)
Definition: util.cpp:57
int exploringBB::SocketClient::send |
( |
std::string |
message | ) |
|
|
virtual |
67 const char *writeBuffer = message.data();
68 int length = message.length();
69 int n =
write(this->socketfd, writeBuffer, length);
71 perror(
"Socket Client: error writing to socket");
int write(string path, string filename, string value)
Definition: util.cpp:40
The documentation for this class was generated from the following files: