Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / colonet / ColonetClient / Client.cpp @ 13

History | View | Annotate | Download (1.73 KB)

1
/**
2
 *
3
 *  @author Jason Knichel
4
 *
5
 * 3/1/07
6
 */
7

    
8
#include <stdlib.h>
9
#include <stdio.h>
10
#include <string.h>
11
#include "includes/Server.h"
12
#include "includes/Client.h"
13
#include "includes/Commands.h"
14
#include "includes/Buzzer.h"
15

    
16

    
17

    
18
//TODO: figure out why it thinks its connected to the server even if we pick some random IP address
19

    
20

    
21
int main(int argc, char * argv[])
22
{
23
  Buzzer buzzer;
24
  if (argc < 3)
25
    {
26
      printf("\nUsage: %s <server address> <port number>\n", argv[0]);
27
      exit(0);
28
    }
29

    
30
  Server colonetServer(argv[1], argv[2]);
31
  if (colonetServer.isError())
32
    {
33
      printf("There was an error initializing a connection to the server.\nError message: %s\n", colonetServer.getErrorMsg());
34
      exit(0);
35
    }
36
  
37
  Commands commands;
38

    
39
  char msgBuffer[MAX_RESPONSE_LEN];
40
  char inputBuffer[MAX_INPUT_LENGTH+1];
41
  
42
  printf("Type \"help\" for information on available commands\n");
43
  while(1)
44
    {
45
      colonetServer.recvMessagesFromServer();
46

    
47
      while(colonetServer.getMsg(msgBuffer, MAX_RESPONSE_LEN) > 0)
48
        {
49
          //buffer now contains a message the server sent to the client.  do something with it
50
        }
51
      if (colonetServer.isError())
52
        {
53
          printf("There was an error:\n%s\n", colonetServer.getErrorMsg());
54
          colonetServer.clearError();
55
        }
56

    
57
      printf("Enter a command: ");
58
      if (fgets(inputBuffer, MAX_INPUT_LENGTH, stdin) == NULL)
59
        {
60
          printf("There was an error reading from standard input.\n");
61
          continue;
62
        }
63
      if(inputBuffer[0] == '\n')
64
        continue;
65

    
66
      if (commands.parseCommand(inputBuffer, colonetServer))
67
        {
68
          printf("There was an error parsing a command.\n");
69
          continue;
70
        }
71
    }
72
  printf("Done.\n");
73
}