134 lines
2.5 KiB
C++
134 lines
2.5 KiB
C++
|
#include "camera.h"
|
||
|
#include "cube.h"
|
||
|
#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 "UDPpacketVBuffer.h"
|
||
|
#include "FileIO.h"
|
||
|
|
||
|
#include <iostream>
|
||
|
#include <fstream>
|
||
|
#include <memory>
|
||
|
#include <vector>
|
||
|
|
||
|
#include <getopt.h> /* getopt */
|
||
|
#include <stdlib.h> /* exit */
|
||
|
#include <string.h> /* memset */
|
||
|
#include <unistd.h> /* getopt */
|
||
|
|
||
|
#include <glm/vec3.hpp>
|
||
|
#include <glm/gtc/type_ptr.hpp>
|
||
|
|
||
|
#define Perf_Diff(a, b) ((double) 1000 * ((double)(((double) (b) - (double) (a)) / (double) SDL_GetPerformanceFrequency ())))
|
||
|
|
||
|
#define MIN_FRAME_MS 7 /* 144 Hz */
|
||
|
|
||
|
static void my_GetOpt (int, char **);
|
||
|
static void my_Usage (const char *);
|
||
|
|
||
|
static const char* host = "localhost";
|
||
|
static Uint16 port = 6666;
|
||
|
static int channel = -1;
|
||
|
static std::string path = "./test/test_UDPpacketVBuffer.cpp";
|
||
|
|
||
|
static std::unique_ptr<UDPbase> client;
|
||
|
|
||
|
int
|
||
|
main (int argc, char **argv)
|
||
|
{
|
||
|
UDPsocket udpsock;
|
||
|
|
||
|
common_Signal_Init ();
|
||
|
my_GetOpt (argc, argv);
|
||
|
|
||
|
common_SDL_Init ();
|
||
|
|
||
|
client = std::make_unique<UDPbase> (host, port);
|
||
|
if (NULL == (udpsock = client->Open (0)))
|
||
|
{
|
||
|
SDL_Log ("Unable to open client port");
|
||
|
return -1;
|
||
|
}
|
||
|
if (-1 == (channel = client->Bind (udpsock, -1)))
|
||
|
{
|
||
|
SDL_Log ("Unable to bind client port");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
std::string buf;
|
||
|
if (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 (path, "r");
|
||
|
buf = f.ReadToString ();
|
||
|
}
|
||
|
UDPpacket* packet = SDLNet_AllocPacket (buf.length ());
|
||
|
IPaddress* addr = SDLNet_UDP_GetPeerAddress (udpsock, channel);
|
||
|
packet->len = DEFAULT_MAX_PACKET_SIZE;
|
||
|
packet->address = *addr;
|
||
|
packet->channel = channel;
|
||
|
UDPpacketVBuffer packetV (packet, &buf[0], buf.length ());
|
||
|
packetV.Send (udpsock);
|
||
|
|
||
|
client->Close (udpsock);
|
||
|
|
||
|
common_SDL_Quit ();
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
static void
|
||
|
my_Usage (const char *argv0)
|
||
|
{
|
||
|
fprintf (stderr, "Usage: %s [-h] [-s host] [-p port]\n", argv0);
|
||
|
}
|
||
|
|
||
|
|
||
|
static void
|
||
|
my_GetOpt (int argc, char **argv)
|
||
|
{
|
||
|
int opt;
|
||
|
host = "localhost";
|
||
|
port = 6666;
|
||
|
while ((opt = getopt (argc, argv, "f:hp:s:")) != -1)
|
||
|
{
|
||
|
switch (opt)
|
||
|
{
|
||
|
case 'p':
|
||
|
port = strtol (optarg, NULL, 0);
|
||
|
break;
|
||
|
case 's':
|
||
|
host = optarg;
|
||
|
break;
|
||
|
case 'f':
|
||
|
path = std::string (optarg);
|
||
|
break;
|
||
|
case 'h':
|
||
|
default:
|
||
|
my_Usage (argv[0]);
|
||
|
exit (EXIT_FAILURE);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|