#include "debug.h" #include "glCheckErrors.h" #include "lib_GL_common.h" #include "lib_SDL_common.h" #include "quad.h" #include "shader.h" #include "signal_common.h" #include "unused.h" #include "UDPbase.h" #include "FileIO.h" #include "SafeUDPpacketV.h" #include "lib_GetOpt.h" #include #include #include #include #include /* exit */ #include /* memset */ #include /* getopt */ #include /* getopt */ #define MIN_FRAME_MS 7 /* 144 Hz */ static const char* host = "localhost"; static Uint16 port = 6666; static int channel = -1; static std::unique_ptr client; struct Test_CommonOpts : public Init_CommonOpts { std::string path; }; static void my_GetOpt (int argc, char** argv, Test_CommonOpts*); static void my_Usage (const char*); int main (int argc, char **argv) { { Test_CommonOpts init_opts; UDPsocket udpsock; common_Signal_Init (); my_GetOpt (argc, argv, &init_opts); common_SDL_Init (); client = std::make_unique (host, port); if (NULL == (udpsock = client->UDP_Open (0))) { SDL_Log ("Unable to open client port"); return -1; } if (-1 == (channel = client->UDP_Bind (udpsock, -1))) { SDL_Log ("Unable to bind client port"); return -1; } std::string buf; if (init_opts.path == "-") { try { std::string line; while (getline (std::cin, line)) { buf += line + "\n"; } } catch (std::ifstream::failure& e) { // std::cout << e << std::endl; } } else { FileIO f (init_opts.path, "r"); buf = f.ReadToString (); } IPaddress* addr = SDLNet_UDP_GetPeerAddress (udpsock, channel); SafeUDPpacketV pV (&buf[0], buf.length (), DEFAULT_MAX_PACKET_SIZE); pV.len (DEFAULT_MAX_PACKET_SIZE); pV.address (*addr); pV.channel (channel); pV.Send (udpsock); } common_SDL_Quit (); return 0; } static void my_Usage (const char* argv0) { fprintf (stderr, "Usage: %s [-h] [-f [-|path]] [-s server] [-p port]\n", argv0); } void my_GetOpt (int argc, char** argv, Test_CommonOpts* state) { int opt; state->host = "localhost"; state->channel = -1; state->mtu = DEFAULT_MAX_PACKET_SIZE; state->port = 6666; state->path = "test/test_SafeUDPpacket.cpp"; while ((opt = getopt (argc, argv, "f:hm:p:s:")) != -1) { switch (opt) { case 'f': state->path = optarg; break; case 'm': state->mtu = strtol (optarg, NULL, 0); break; case 'p': state->port = strtol (optarg, NULL, 0); break; case 's': state->host = optarg; break; default: case 'h': my_Usage (argv[0]); exit (EXIT_FAILURE); break; } } }