#include "udp.h"
#include <cstdlib>
#include <cstring>

using namespace std;
using namespace net_tools;

int
main(int argc, char ** argv)
{
   if(argc != 2) {
      cerr << "usage: udp_test -recv | -send" << endl;
      exit(1);
   }
   if(strcmp(argv[1], "-recv") == 0) {
      udp_socket server("127.0.0.1", 1033, udp_socket::UDP_SERVER);
      char buffer[512];
      memset(buffer, 0, 512);
      server.recive(buffer, 512);
      cout << buffer << endl;
   }
   else if(strcmp(argv[1], "-send") == 0) {
      udp_socket client("127.0.0.1", 1033, udp_socket::UDP_CLIENT);
      char buffer[512];
      memset(buffer, 0, 512);
      strcpy(buffer, "Hello, world!");
      client.send(buffer, 512);
   }
   return 0;
}
