Started working on a simple UDP wrapper
This commit is contained in:
@@ -17,12 +17,32 @@ using ';' delimited commands, how can I get it to work?
|
||||
|
||||
-------------------------
|
||||
|
||||
UDPNetworkManager: //don't worry at this stage
|
||||
Open(port)
|
||||
Close()
|
||||
UDPNetworkUtility:
|
||||
void Open(port, packSize)
|
||||
void Close()
|
||||
|
||||
Send(ip, port)
|
||||
Receive()
|
||||
//bind to an available channel
|
||||
int Bind(ip, port)
|
||||
int Bind(address)
|
||||
|
||||
//bind to a certain channel
|
||||
int Bind(ip, port, channel)
|
||||
int Bind(address, channel)
|
||||
void Unbind(channel)
|
||||
|
||||
int Send(channel, data, len)
|
||||
int Receive()
|
||||
|
||||
GetIPAddress(channel)
|
||||
|
||||
GetOutData()
|
||||
GetInData()
|
||||
GetInData()
|
||||
|
||||
GetOutPacket()
|
||||
GetInPacket()
|
||||
|
||||
UDPsocket socket
|
||||
UDPpacket packOut
|
||||
UDPpacket packIn
|
||||
end
|
||||
|
||||
|
||||
@@ -24,10 +24,10 @@
|
||||
#ifndef _SDL_NET_H
|
||||
#define _SDL_NET_H
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_endian.h"
|
||||
#include "SDL_version.h"
|
||||
#include "begin_code.h"
|
||||
#include "SDL/SDL.h"
|
||||
#include "SDL/SDL_endian.h"
|
||||
#include "SDL/SDL_version.h"
|
||||
#include "SDL/begin_code.h"
|
||||
|
||||
|
||||
|
||||
@@ -157,9 +157,9 @@ extern DECLSPEC void SDLCALL SDLNet_TCP_Close(TCPsocket sock);
|
||||
/***********************************************************************/
|
||||
|
||||
/* The maximum channels on a a UDP socket */
|
||||
#define SDLNET_MAX_UDPCHANNELS 32
|
||||
#define SDLNET_MAX_UDPCHANNELS 150
|
||||
/* The maximum addresses bound to a single UDP socket channel */
|
||||
#define SDLNET_MAX_UDPADDRESSES 4
|
||||
#define SDLNET_MAX_UDPADDRESSES 1
|
||||
|
||||
typedef struct _UDPsocket *UDPsocket;
|
||||
typedef struct {
|
||||
@@ -447,6 +447,6 @@ do \
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
#include "SDL/close_code.h"
|
||||
|
||||
#endif /* _SDL_NET_H */
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "SDL_endian.h"
|
||||
#include "SDL/SDL_endian.h"
|
||||
|
||||
#include "SDLnetsys.h"
|
||||
#include "SDL_net.h"
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
SRC=$(wildcard *.c)
|
||||
OBJ=$(SRC:.c=.o)
|
||||
OUT = libSDL_net.a
|
||||
|
||||
all: $(OBJ)
|
||||
ar -crs $(OUT) $(OBJ)
|
||||
|
||||
$(%.o): %.c
|
||||
$(CC) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
$(RM) *.o *.a
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifndef UDPNETWORKUTILITY_HPP_
|
||||
#define UDPNETWORKUTILITY_HPP_
|
||||
|
||||
#include "SDL_net/SDL_net.h"
|
||||
|
||||
class UDPNetworkUtility {
|
||||
public:
|
||||
UDPNetworkUtility() = default;
|
||||
~UDPNetworkUtility() = default;
|
||||
|
||||
void Open(int port, int packSize);
|
||||
void Close();
|
||||
|
||||
//bind to an available channel
|
||||
int Bind(const char* ip, int port) {
|
||||
Bind(ip, port, -1);
|
||||
}
|
||||
int Bind(IPaddress add) {
|
||||
Bind(add, -1);
|
||||
}
|
||||
|
||||
//bind to certain channel
|
||||
int Bind(const char* ip, int port, int channel);
|
||||
int Bind(IPaddress add, int channel);
|
||||
void Unbind(int channel);
|
||||
|
||||
IPaddress* GetIPAddress(int channel) {
|
||||
return SDLNet_GetPeerAddress(socket, channel);
|
||||
}
|
||||
|
||||
int Send(int channel, void* data, int len);
|
||||
int Receive();
|
||||
|
||||
void* GetOutData() const {
|
||||
return reinterpret_cast<void*>(packOut->data);
|
||||
};
|
||||
void* GetInData() const {
|
||||
return reinterpret_cast<void*>(packIn->data);
|
||||
};
|
||||
void* GetOutPacket() const {
|
||||
return packOut;
|
||||
}
|
||||
void* GetInPacket() const {
|
||||
return packIn;
|
||||
}
|
||||
private:
|
||||
UDPsocket socket = nullptr;
|
||||
UDPpacket* packOut = nullptr;
|
||||
UDPpacket* packIn = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user