VICI  0.11.815
Visual Chart Interpreter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
udpsocket.h
Go to the documentation of this file.
1 
2 /*
3  * udpsocket.h
4  *
5  * Copyright 2008 - 2016 Brenton Ross
6  *
7  * This file is part of VICI.
8  *
9  * VICI is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * VICI is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with VICI. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
27 // ---------------------------------------------------------
28 
29 #ifndef CFI_UDPSOCKET_H
30 #define CFI_UDPSOCKET_H
31 
32 // ----------------------------------------------------------------
33 
34 #include "stringy.h"
35 #include <sys/socket.h>
36 #include <netinet/in.h>
37 
38 // ----------------------------------------------------------------
39 
40 
41 namespace VICI
42 {
43 
44 namespace cfi
45 {
46 
48 
56 class UDPSocket
57 {
58 public:
59  //
63  //
64  static const int BUFFER_SIZE = 16000;
65 
66 private:
67  char *buffer;
68 
69  // protect against copying sockets
70  UDPSocket( const UDPSocket & ) = delete;
71  void operator = ( const UDPSocket & ) = delete;
72 
73 protected:
74  struct sockaddr_in addr;
75  unsigned int addr_len;
76  int sd;
77 
79  UDPSocket();
80 public:
82  virtual ~UDPSocket();
83 
85  int fd() { return sd; }
86 
88 
91  void send( csr message );
92 
94 
99  void recv( std::string &message, std::string &host, int &port );
100 };
101 
102 // ----------------------------------------------------------------
103 
105 
111 {
112 public:
114 
118  UDPClientSocket( csr host, int portid );
119 };
120 
121 // ----------------------------------------------------------------
122 
124 
131 {
132 public:
134 
137  UDPServerSocket( int portid );
138 
140 
145  void send( csr message, csr host, int port );
146 };
147 
148 // ----------------------------------------------------------------
149 
150 } // namespace cfi
151 } // namespace VICI
152 
153 #endif
154 
155 // --------------------------------- end ---------------------------
156 
UDPClientSocket(csr host, int portid)
Constructor.
Definition: udpsocket.cpp:104
static const int BUFFER_SIZE
Definition: udpsocket.h:64
A UDP Server socket.
Definition: udpsocket.h:130
void send(csr message)
send a message via the socket&#39;s file descriptor
Definition: udpsocket.cpp:70
UDPServerSocket(int portid)
Constructor.
Definition: udpsocket.cpp:132
Useful string functions.
virtual ~UDPSocket()
destructor
Definition: udpsocket.cpp:61
An abstract base class with common stuff for UDP sockets.
Definition: udpsocket.h:56
int fd()
get the file descriptor for the socket
Definition: udpsocket.h:85
A UDP client socket.
Definition: udpsocket.h:110
UDPSocket()
constructor
Definition: udpsocket.cpp:48
void recv(std::string &message, std::string &host, int &port)
wait for the next incoming message
Definition: udpsocket.cpp:84
struct sockaddr_in addr
internal address structure
Definition: udpsocket.h:74
void send(csr message, csr host, int port)
send message to specified host and port. Used for replies.
Definition: udpsocket.cpp:148
unsigned int addr_len
size of address structure
Definition: udpsocket.h:75
const std::string & csr
short cut for string constants
Definition: vici.h:80
int sd
file descriptor
Definition: udpsocket.h:76