diff options
Diffstat (limited to 'test/04Network/main.cpp')
-rw-r--r-- | test/04Network/main.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/test/04Network/main.cpp b/test/04Network/main.cpp new file mode 100644 index 0000000..6db72ab --- /dev/null +++ b/test/04Network/main.cpp @@ -0,0 +1,84 @@ +#include <iostream> +#include <functional> +#include "jin.h" + +using namespace std; +using namespace jin::core; +using namespace jin::graphics; +using namespace jin::input; +using namespace jin::audio; +using namespace jin::time; +using namespace jin::thread; +using namespace jin::net; + +Timers timers; + +void onEvent(jin::input::Event* e) +{ + static Game* game = Game::get(); + if (e->type == EventType::QUIT) + game->stop(); +} + +void onUpdate(int ms) +{ + timers.update(ms); +} + +void onDraw() +{ + +} + +void netWorkThread(Thread* t) +{ + Thread::Variant v = t->demand(1); + Socket* socket = (Socket*)v.pointer; + char buffer[2048] = {0}; + while (true) + { + Socket* client = socket->accept(); + if (client != nullptr) + { + client->receive(buffer, sizeof(buffer)); + cout << buffer; + } + } +} + +int main(int argc, char* argv[]) +{ + Game* game = Game::get(); + Game::Setting setting; + setting.eventHandler = onEvent; + setting.updater = onUpdate; + setting.drawer = onDraw; + setting.loader = nullptr; + game->init(&setting); + + Window* wnd = Window::get(); + Window::Setting wndSetting; + wndSetting.width = 400; + wndSetting.height = 300; + wndSetting.title = "test"; + wndSetting.fps = 60; + wndSetting.vsync = false; + wndSetting.fullscreen = false; + wndSetting.resizable = true; + wnd->init(&wndSetting); + + Net::get()->init(nullptr); + + Socket socket(SocketType::TCP, 6438); + + Thread t("Receive Network Data", netWorkThread); + t.start(); + t.send(1, &socket); + + game->run(); + + game->quit(); + wnd->quit(); + + return 0; +}
\ No newline at end of file |