Exploring BeagleBone  V1.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SocketClient.h
Go to the documentation of this file.
1 /*
2  * SocketClient.h Created on: 2 Jul 2014
3  * Copyright (c) 2014 Derek Molloy (www.derekmolloy.ie)
4  * Made available for the book "Exploring BeagleBone"
5  * See: www.exploringbeaglebone.com
6  * Licensed under the EUPL V.1.1
7  *
8  * This Software is provided to You under the terms of the European
9  * Union Public License (the "EUPL") version 1.1 as published by the
10  * European Union. Any use of this Software, other than as authorized
11  * under this License is strictly prohibited (to the extent such use
12  * is covered by a right of the copyright holder of this Software).
13  *
14  * This Software is provided under the License on an "AS IS" basis and
15  * without warranties of any kind concerning the Software, including
16  * without limitation merchantability, fitness for a particular purpose,
17  * absence of defects or errors, accuracy, and non-infringement of
18  * intellectual property rights other than copyright. This disclaimer
19  * of warranty is an essential part of the License and a condition for
20  * the grant of any rights to this Software.
21  *
22  * For more details, see http://www.derekmolloy.ie/
23  */
24 
25 #ifndef SOCKETCLIENT_H_
26 #define SOCKETCLIENT_H_
27 
28 #include <sys/socket.h>
29 #include <sys/types.h>
30 #include <netinet/in.h>
31 #include <netdb.h>
32 #include <string>
33 
34 namespace exploringBB {
35 
40 class SocketClient {
41 
42 private:
43  int socketfd;
44  struct sockaddr_in serverAddress;
45  struct hostent *server;
46  std::string serverName;
47  int portNumber;
48  bool isConnected;
49 
50 public:
51  SocketClient(std::string serverName, int portNumber);
52  virtual int connectToServer();
53  virtual int disconnectFromServer();
54  virtual int send(std::string message);
55  virtual std::string receive(int size);
56  //virtual std::string receiveAll();
57  bool isClientConnected() { return this->isConnected; }
58  virtual ~SocketClient();
59 };
60 
61 } /* namespace exploringBB */
62 
63 #endif /* SOCKETCLIENT_H_ */
virtual int send(std::string message)
Definition: SocketClient.cpp:66
virtual std::string receive(int size)
Definition: SocketClient.cpp:77
bool isClientConnected()
Definition: SocketClient.h:57
SocketClient(std::string serverName, int portNumber)
Definition: SocketClient.cpp:33
virtual ~SocketClient()
Definition: SocketClient.cpp:111
virtual int connectToServer()
Definition: SocketClient.cpp:41
Definition: BusDevice.cpp:27
A class that encapsulates a socket client to be used for network communication.
Definition: SocketClient.h:40
virtual int disconnectFromServer()
Definition: SocketClient.cpp:105