TestSocket.cpp



/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 2 -*- */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <socket.hpp>

int main(int argc, char *argv[])
{
  
  if(argc<2)
  {
    puts("\nUSE:\nTestSocket <type>\n");
    puts("types:");
    puts("\tserver <ip> <port>");
    puts("\tclient <ip> <port> <cadena>\n");
    puts("\t  e.g.");
    puts("\t    TestSocket server localhost 13000 => Waits on port 13000 a client tcp.");
    puts("\t    TestSocket client localhost 13000 \"a pair of words\" => Sends 'a pair of words' to a server tcp on localhost with port 13000 .\n");

    exit(EXIT_SUCCESS);
  }

  if(strcmp(argv[1],"server")==0)
  {
    char* buffer;
    buffer=(char*)malloc(1024*sizeof(char));
    CMSocket algo(atoi(argv[3]),argv[2],1024);
    algo.serverTcp();
    algo.serverRead(buffer);
    printf("%s\n",buffer);
    free(buffer);
    exit(EXIT_SUCCESS);
  }

  if(strcmp(argv[1],"client")==0)
  {
    CMSocket algo(atoi(argv[3]),argv[2],1024);
    algo.clientTcp();
    algo.clientWrite(argv[4]);
    exit(EXIT_SUCCESS);
  }
  
}
 All Data Structures Functions Variables
Generated on Mon Sep 12 07:59:09 2011 for API MokArdu by  doxygen 1.6.3