WPILibC++  unspecified
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/StringRef.h"
15 #include "wpi/Twine.h"
16 #include "wpi/mutex.h"
17 
18 namespace wpi {
19 
20 class Logger;
21 
22 class UDPClient {
23  int m_lsd;
24  std::string m_address;
25  Logger& m_logger;
26 
27  public:
28  explicit UDPClient(Logger& logger);
29  UDPClient(const Twine& address, Logger& logger);
30  UDPClient(const UDPClient& other) = delete;
31  UDPClient(UDPClient&& other);
32  ~UDPClient();
33 
34  UDPClient& operator=(const UDPClient& other) = delete;
35  UDPClient& operator=(UDPClient&& other);
36 
37  int start();
38  void shutdown();
39  // The passed in address MUST be a resolved IP address.
40  int send(ArrayRef<uint8_t> data, const Twine& server, int port);
41  int send(StringRef data, const Twine& server, int port);
42 };
43 
44 } // namespace wpi
45 
46 #endif // WPIUTIL_WPI_UDPCLIENT_H_
Definition: UDPClient.h:22
namespace to hold default to_json function
Definition: json_binary_writer.cpp:39
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