WPILibC++  2019.2.1-3-g1349dd4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
UDPClient.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #ifndef WPIUTIL_WPI_UDPCLIENT_H_
9 #define WPIUTIL_WPI_UDPCLIENT_H_
10 
11 #include <string>
12 
13 #include "wpi/ArrayRef.h"
14 #include "wpi/SmallVector.h"
15 #include "wpi/StringRef.h"
16 #include "wpi/Twine.h"
17 #include "wpi/mutex.h"
18 
19 namespace wpi {
20 
21 class Logger;
22 
23 class UDPClient {
24  int m_lsd;
25  int m_port;
26  std::string m_address;
27  Logger& m_logger;
28 
29  public:
30  explicit UDPClient(Logger& logger);
31  UDPClient(const Twine& address, Logger& logger);
32  UDPClient(const UDPClient& other) = delete;
33  UDPClient(UDPClient&& other);
34  ~UDPClient();
35 
36  UDPClient& operator=(const UDPClient& other) = delete;
37  UDPClient& operator=(UDPClient&& other);
38 
39  int start();
40  int start(int port);
41  void shutdown();
42  // The passed in address MUST be a resolved IP address.
43  int send(ArrayRef<uint8_t> data, const Twine& server, int port);
44  int send(StringRef data, const Twine& server, int port);
45  int receive(uint8_t* data_received, int receive_len);
46  int receive(uint8_t* data_received, int receive_len,
47  SmallVectorImpl<char>* addr_received, int* port_received);
48  int set_timeout(double timeout);
49 };
50 
51 } // namespace wpi
52 
53 #endif // WPIUTIL_WPI_UDPCLIENT_H_
Definition: UDPClient.h:23
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Definition: Logger.h:30
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79