Wrapper completed & tested; adjusted many systems
This commit is contained in:
+8
-6
@@ -14,8 +14,13 @@ OBJ=$(addprefix $(OBJDIR)/,$(SRC:.cpp=.o))
|
||||
OUTDIR=out
|
||||
|
||||
#targets
|
||||
all: $(OBJ) $(OUT)
|
||||
$(CXX) $(CXXFLAGS) -o $(OUTDIR)/server main.cpp $(OBJ) $(LIB)
|
||||
all: server unit
|
||||
|
||||
server: $(OBJ) $(OUT)
|
||||
$(CXX) $(CXXFLAGS) -o $(OUTDIR)/$@ main.cpp $(OBJ) $(LIB)
|
||||
|
||||
unit: $(OBJ) $(OUT)
|
||||
$(CXX) $(CXXFLAGS) -o $(OUTDIR)/$@ unit.cpp $(OBJ) $(LIB)
|
||||
|
||||
$(OBJ): | $(OBJDIR)
|
||||
|
||||
@@ -33,7 +38,4 @@ $(OBJDIR)/%.o: %.cpp
|
||||
clean:
|
||||
$(RM) *.o *.a *.exe
|
||||
|
||||
rebuild: clean all unit
|
||||
|
||||
unit: $(OBJ) $(OUT)
|
||||
$(CXX) $(CXXFLAGS) -o $(OUTDIR)\unit unit.cpp $(OBJ) $(LIB)
|
||||
rebuild: clean all
|
||||
|
||||
+10
-2
@@ -6,7 +6,11 @@
|
||||
using namespace std;
|
||||
|
||||
void Server::Init() {
|
||||
if (SDLNet_Init()) {
|
||||
throw(runtime_error("Failed to initialize SDL_net"));
|
||||
}
|
||||
config.Load("config.cfg");
|
||||
netUtil.Open(config.Integer("port"), 512);
|
||||
running = true;
|
||||
}
|
||||
|
||||
@@ -17,15 +21,19 @@ void Server::Proc() {
|
||||
HandleOutput();
|
||||
|
||||
//debug
|
||||
running = false;
|
||||
// running = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Server::Quit() {
|
||||
//
|
||||
netUtil.Close();
|
||||
SDLNet_Quit();
|
||||
}
|
||||
|
||||
void Server::HandleInput() {
|
||||
while(netUtil.Receive()) {
|
||||
cout << reinterpret_cast<char*>(netUtil.GetInData()) << endl;
|
||||
}
|
||||
//accept new connections
|
||||
//accept updates from the clients
|
||||
//read the updates from the clients into internal containers
|
||||
|
||||
+2
-2
@@ -1,10 +1,9 @@
|
||||
#ifndef SERVER_HPP_
|
||||
#define SERVER_HPP_
|
||||
|
||||
#include "udp_network_utility.hpp"
|
||||
#include "config_utility.hpp"
|
||||
|
||||
#include <list>
|
||||
|
||||
class Server {
|
||||
public:
|
||||
Server() = default;
|
||||
@@ -20,6 +19,7 @@ public:
|
||||
private:
|
||||
bool running = false;
|
||||
ConfigUtility config;
|
||||
UDPNetworkUtility netUtil;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+19
-2
@@ -1,9 +1,26 @@
|
||||
#include "udp_network_utility.hpp"
|
||||
|
||||
#include "SDL_net/SDL_net.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//receive any amount of info and print it
|
||||
|
||||
int main(int, char**) {
|
||||
if (SDLNet_Init()) {
|
||||
cerr << "Failed to init SDL_net" << endl;
|
||||
return -1;
|
||||
}
|
||||
UDPNetworkUtility netUtil;
|
||||
|
||||
netUtil.Open(0, 512);
|
||||
|
||||
string s = "Hello world";
|
||||
netUtil.Send("127.0.0.1", 2000, (void*)s.c_str(), s.length());
|
||||
|
||||
netUtil.Close();
|
||||
|
||||
SDLNet_Quit();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user