Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / colonet / ColonetClient / includes / Server.h @ 13

History | View | Annotate | Download (1.32 KB)

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

    
8
#ifndef SERVER_H
9
#define SERVER_H
10

    
11
#include "../../lib/colonet_defs.h"
12

    
13
#define MAX_ERROR_MSG_LEN 256
14
#define MIN_PORT 1024
15
#define MAX_PORT 65536
16
#define MAX_RESPONSES_QUEUE 8
17
#define READ_BUFFER_SIZE (MAX_RESPONSE_LEN * MAX_RESPONSES_QUEUE)
18

    
19
//Error codes
20
#define ERROR_SERVER_PARAMETER_NULL -1
21
#define ERROR_SERVER_MESSAGE_LENGTH -2
22
#define ERROR_SERVER_SOCKET         -3
23
#define ERROR_SERVER_SENDING        -4
24
#define ERROR_SERVER_READING        -5
25
#define ERROR_SERVER_BUFFER_LENGTH  -6
26
#define ERROR_SERVER_MESSAGE_TOO_LONG -7
27
#define ERROR_SERVER_NOT_ENOUGH_ROOM -8
28
#define ERROR_NO_NEWLINE            -9
29

    
30

    
31
class Server
32
{
33
 public:
34
  Server(char * serverAddress, char * port);
35
  Server(int ipAdress, unsigned short port);
36

    
37
  //sends a message to the server you are connected to
38
  int sendMsg(char * message);
39
  //try to read something from the server you are connected to and buffer it
40
  int recvMessagesFromServer();
41
  //getMsg - returns the next message in the readBuffer
42
  int getMsg(char * buffer, int bufferLen);
43

    
44
  int isError();
45
  char * getErrorMsg();
46
  void clearError();
47

    
48
 private:
49
  void initializeServer(int ipAddress, unsigned short port);
50

    
51
  int serverSocket;
52
  int error;
53
  char errorMsg[MAX_ERROR_MSG_LEN];
54

    
55
  char readBuffer[READ_BUFFER_SIZE];
56
  int readBufferLength;
57
};
58

    
59

    
60

    
61
#endif