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-08 21:23:42 -05:00
|
|
|
#define DEFAULT_MAX_PACKET_SIZE 250
|
2022-01-08 18:59:40 -05:00
|
|
|
|
|
|
|
class UDPbase
|
|
|
|
{
|
2022-01-13 12:15:07 -05:00
|
|
|
int mChannel;
|
2022-01-09 23:37:48 -05:00
|
|
|
IPaddress mIPAddress;
|
2022-01-13 12:15:07 -05:00
|
|
|
protected:
|
|
|
|
std::vector<UDPsocket> UDPsocks;
|
2022-01-08 18:59:40 -05:00
|
|
|
public:
|
2022-01-08 21:23:42 -05:00
|
|
|
UDPbase (const char* host, const Uint16 port);
|
2022-01-13 12:15:07 -05:00
|
|
|
UDPbase (const char* host, const Uint16 port, const int channel);
|
2022-01-08 21:23:42 -05:00
|
|
|
~UDPbase (void);
|
2022-01-13 12:15:07 -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);
|
|
|
|
|
|
|
|
void CloseAllSockets (void);
|
|
|
|
|
|
|
|
int getChannel (void) const { return mChannel; }
|
|
|
|
UDPsocket getSocket (const size_t idx) const { return UDPsocks.at (idx); }
|
|
|
|
|
2022-01-08 21:23:42 -05:00
|
|
|
std::string toString (void);
|
2022-01-08 18:59:40 -05:00
|
|
|
};
|