WPILibC++ 2024.3.2
UDPClient.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#ifndef WPINET_UDPCLIENT_H_
6#define WPINET_UDPCLIENT_H_
7
8#include <span>
9#include <string>
10#include <string_view>
11
12#include <wpi/SmallVector.h>
13#include <wpi/mutex.h>
14
15namespace wpi {
16
17class Logger;
18
19class UDPClient {
20 int m_lsd;
21 int m_port;
22 std::string m_address;
23 Logger& m_logger;
24
25 public:
26 explicit UDPClient(Logger& logger);
28 UDPClient(const UDPClient& other) = delete;
31
32 UDPClient& operator=(const UDPClient& other) = delete;
34
35 int start();
36 int start(int port);
37 void shutdown();
38 // The passed in address MUST be a resolved IP address.
39 int send(std::span<const uint8_t> data, std::string_view server, int port);
40 int send(std::string_view data, std::string_view server, int port);
41 int receive(uint8_t* data_received, int receive_len);
42 int receive(uint8_t* data_received, int receive_len,
43 SmallVectorImpl<char>* addr_received, int* port_received);
44 int set_timeout(double timeout);
45};
46
47} // namespace wpi
48
49#endif // WPINET_UDPCLIENT_H_
This file defines the SmallVector class.
Definition: Logger.h:27
Definition: UDPClient.h:19
UDPClient & operator=(const UDPClient &other)=delete
UDPClient(const UDPClient &other)=delete
int set_timeout(double timeout)
UDPClient(std::string_view address, Logger &logger)
UDPClient(Logger &logger)
int start(int port)
UDPClient & operator=(UDPClient &&other)
int send(std::span< const uint8_t > data, std::string_view server, int port)
int send(std::string_view data, std::string_view server, int port)
UDPClient(UDPClient &&other)
int receive(uint8_t *data_received, int receive_len, SmallVectorImpl< char > *addr_received, int *port_received)
int receive(uint8_t *data_received, int receive_len)
basic_string_view< char > string_view
Definition: core.h:501
Definition: ntcore_cpp.h:26