6a8f90500f
< Bubblegumdrop> SDLNet_UDP_Open seems to call SDLNet_Read16 (which is just SDL_SwapBE16) < Bubblegumdrop> But on the server side I don't use SDLNet_UDP_Open to host the port < whitt> probably the sender was flipping it but the receiver wasn't and so they were incompatible < Bubblegumdrop> removing the SDL_SwapBE16 on the client side fixed it
51 lines
1020 B
C++
51 lines
1020 B
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <SDL.h>
|
|
#include <SDL_net.h>
|
|
|
|
/* MTU */
|
|
#define MAX_PACKET_SIZE (1024*1024)
|
|
|
|
class Server
|
|
{
|
|
SDL_mutex* mProcessPacketMutex;
|
|
SDL_TimerID mProcessPacketCallbackTimerID;
|
|
static Uint32 ProcessPacketCallback (Uint32, void*);
|
|
public:
|
|
std::vector<UDPsocket> UDPsocks;
|
|
SDLNet_SocketSet SocketSet;
|
|
UDPpacket **UDPPacketV;
|
|
Server (void)
|
|
{
|
|
UDPsocks.clear ();
|
|
SocketSet = NULL;
|
|
UDPPacketV = NULL;
|
|
mProcessPacketMutex = NULL;
|
|
}
|
|
~Server (void)
|
|
{
|
|
// UDP_CloseAll ();
|
|
// mProcessPacketMutex = SDL_CreateMutex ();
|
|
// UDPsocks.clear ();
|
|
// SocketSet = NULL;
|
|
// UDPPacketV = NULL;
|
|
}
|
|
Server (const char* host, const Uint16 port);
|
|
UDPsocket UDP_Open (Uint16 port);
|
|
void UDP_CloseAll (void);
|
|
void ProcessPacket (UDPpacket* packet);
|
|
int Start (void);
|
|
int Stop (void);
|
|
int Lock (void)
|
|
{
|
|
return SDL_LockMutex (mProcessPacketMutex);
|
|
}
|
|
int Unlock (void)
|
|
{
|
|
return SDL_UnlockMutex (mProcessPacketMutex);
|
|
}
|
|
};
|