-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomm.h
64 lines (46 loc) · 1.62 KB
/
comm.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
#ifndef _COMM_H
#define _COMM_H
#include "global.h"
#include "board.h"
#include "move.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
/**********************************************************/
#define MAXPENDING 10
/**********************************************************/
#define NM_NEW_POSITION 1
#define NM_COLOR_W 2
#define NM_COLOR_B 3
#define NM_REQUEST_MOVE 4
#define NM_PREPARE_TO_RECEIVE_MOVE 5
#define NM_REQUEST_NAME 6
#define NM_QUIT 7
/**********************************************************/
extern char * port;
/**********************************************************/
void listenToSocket( char * port, int * mySocket );
//creates a socket and starts to listen (used by server)
int acceptConnection( int mySocket );
//accepts new connections (used by server)
void connectToTarget( char * port, char * ip, int * mySocket );
//connects to a server (used by client)
int sendMsg( int msg, int mySocket );
//sends a network message (one char)
int recvMsg( int mySocket );
//receives a network message
int sendMove( Move * moveToSend, int mySocket );
//sends a move via mySocket
int getMove( Move * moveToGet, int mySocket );
//receives a move from mySocket
void sendName( char textToSend[ MAX_NAME_LENGTH + 1 ], int mySocket );
//used to send agent's name to server
int getName( char textToGet[ MAX_NAME_LENGTH + 1 ], int mySocket );
//used to receive agent's name
int sendPosition( Position * posToSend, int mySocket );
//used to send position struct
void getPosition( Position * posToGet, int mySocket );
//used to receive position struct
#endif