2022-01-08 18:59:40 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2022-01-13 12:15:07 -05:00
|
|
|
#include <vector>
|
|
|
|
|
2022-01-08 18:59:40 -05:00
|
|
|
#include <SDL_net.h>
|
|
|
|
|
2022-01-16 14:40:20 -05:00
|
|
|
#define DEFAULT_MAX_PACKET_SIZE 512
|
2022-01-08 18:59:40 -05:00
|
|
|
|
2022-01-16 14:40:20 -05:00
|
|
|
class
|
|
|
|
UDPbase
|
2022-01-08 18:59:40 -05:00
|
|
|
{
|
2022-01-16 17:47:04 -05:00
|
|
|
int m_channel;
|
|
|
|
IPaddress m_address;
|
|
|
|
void CloseAllSockets (void);
|
2022-01-16 14:40:20 -05:00
|
|
|
|
2022-01-13 12:15:07 -05:00
|
|
|
protected:
|
2022-01-16 17:47:04 -05:00
|
|
|
std::vector<UDPsocket> m_socks;
|
2022-01-08 18:59:40 -05:00
|
|
|
public:
|
2022-01-16 17:47:04 -05:00
|
|
|
UDPbase (const char*, const Uint16);
|
|
|
|
UDPbase (const char*, const Uint16, const int);
|
2022-01-08 21:23:42 -05:00
|
|
|
~UDPbase (void);
|
2022-01-13 12:15:07 -05:00
|
|
|
|
2022-01-16 17:47:04 -05:00
|
|
|
int ResolveHost (IPaddress*, const char*, const Uint16);
|
|
|
|
|
|
|
|
UDPsocket UDP_Open (void);
|
|
|
|
UDPsocket UDP_Open (const Uint16 port);
|
|
|
|
|
|
|
|
void UDP_Close (UDPsocket sock);
|
|
|
|
|
|
|
|
int UDP_Bind (UDPsocket sock, const int channel);
|
|
|
|
void UDP_Unbind (UDPsocket sock, const int channel);
|
|
|
|
|
|
|
|
IPaddress* UDP_GetPeerAddress (UDPsocket sock, const int channel);
|
|
|
|
|
|
|
|
/* ======================================================= */
|
|
|
|
int channel (void) const
|
2022-01-16 14:40:20 -05:00
|
|
|
{
|
2022-01-16 17:47:04 -05:00
|
|
|
return m_channel;
|
2022-01-16 14:40:20 -05:00
|
|
|
}
|
2022-01-16 17:47:04 -05:00
|
|
|
|
|
|
|
UDPsocket get (const size_t idx) const
|
2022-01-16 14:40:20 -05:00
|
|
|
{
|
2022-01-16 17:47:04 -05:00
|
|
|
return m_socks.at (idx);
|
2022-01-16 14:40:20 -05:00
|
|
|
}
|
|
|
|
|
2022-01-16 17:47:04 -05:00
|
|
|
std::string toString (void);
|
2022-01-08 18:59:40 -05:00
|
|
|
};
|