-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver_functions.h
116 lines (102 loc) · 2.57 KB
/
server_functions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef SERVER_FUNCTIONS_H
#define SERVER_FUNCTIONS_H
#include <stdio.h>
#include <iostream>
#include <assert.h>
#include <sys/timeb.h>
#include <memory.h>
#include <winsock2.h>
#include <string.h>
#include <time.h>
#include "server_commands.h"
#include "command_def.h"
//=============================================================================
// Server Functions
//=============================================================================
/*
*Tokenize
*
*A helper function that breaks up a string into many substrings
*based on a delimiter character [t].
*String Tokenizers are popular concepts and tools in expression parsing.
*This particular version returns [n]th token [r] of the string [s] of
*length [len] delimited by the character [t].
*
*Multiple contiguous delimiters found in the string
*are not considered as a token and discarded.
*
*Pre:
*Post:
*
*Returns: The length of [r]
*/
int Tokenize(const char* const s,int len,int n,char* r,const char t);
/*
*RcvLine
*
*Receives a line of text from the socket [s] and places in a buffer [buff]
*
*
*Pre:
*Post:
*
*Returns: The number of bytes read, or -1 if an error occured
*/
int RcvLine(SOCKET s,char* buff);
/*
*SendLine
*
*sends a line of text stored in [buff] from the socket [s] of length [len]
*
*SendMethod [m] can be either
TERM_STD: standard newline/carriage return is appended to the text
HEADER_NOTERM: a 2-byte header contain the number of bytes following
*
*Pre:
*Post:
*
*Returns: The number of bytes sent, or -1 if an error occured
*/
int SndLine(SOCKET s,const char* buff,int len,SENDMETHOD m);
/*
*SendData
*
*sends binary image data stored in [buff] from the socket [s] with horizontal and vertical size [xsize] and [ysize]
*A 4 byte header that contains xsize and ysize is send first.
*
*Pre:
*Post:
*
*Returns: The number of bytes sent, or -1 if an error occured
*/
int SndData(SOCKET s,const char* buff,int len,unsigned short xsize,unsigned short ysize);
/*
*SendByte
*
*sends a single byte of data in [c]
*
*Pre:
*Post:
*
*Returns: The number of bytes sent, or -1 if an error occured
*/
int SndByte(SOCKET s,const char c);
/*
*Send_CommandList
*
*sends a list of available server commands to client using SndLine
*Pre:
*Post:
*
*/
void Send_CommandList(SOCKET s);
/*
*Process_Request
*
*processes a text command from the client by parsing the command into command name and parameters
*and then performs tasks based on the command.
*Pre:
*Post:
*/
void Process_Request(SOCKET s);
#endif