-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
41 lines (34 loc) · 903 Bytes
/
common.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
/* common.h
*
* Synopsis: Contains constants and declarations for
* socket helper functions.
*
* Author: Okusanya Oluwadamilola
*
* Date: 9/21/15
*/
#ifndef COMMON_H_
#define COMMON_H_
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sstream>
#include <string.h>
static const unsigned PORT = 9999;
static const char MESSAGE_DISPLAY = 'D';
static const char MESSAGE_PROMPT = 'P';
static const char MESSAGE_TERMINATE = 'X';
struct Message
{
char type;
std::string data;
};
// These two functions implement a primitive protocol;
// messages traveling in either direction are prepended
// with a single-character message type and a 4-digit
// ASCII integer representing the message's length:
// D0003MSG, P0011ENTER MOVE:, etc...
ssize_t socket_write(int fd, std::string data = "",
char type = MESSAGE_DISPLAY);
Message socket_read(int fd);
#endif