-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocket.h
More file actions
49 lines (40 loc) · 929 Bytes
/
Socket.h
File metadata and controls
49 lines (40 loc) · 929 Bytes
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
#pragma once
/*
* Sarah Asad
* Term Project: Tic-Tac-Toe
* Socket.h
*
* This file contains all the method definitiosn for Socket.cpp. It handles all the sends and recieve communication by the
* socket from the client and the server.
*/
#include "SocketException.h"
#include "ByteBuffer.h"
#include "Game.h"
#include <memory>
class Socket {
protected:
int sd;
public:
//constructor
Socket(int sd = -1) {
this->sd = sd;
}
//desctructoe = closes the socket
~Socket() {
if (this->sd != -1) {
close(this->sd);
this->sd = -1;
}
}
//helper method for testing - checking socket value
int getSd() {
return this->sd;
}
void receive(void* buffer, int size);
int readInt();
std::string readString();
std::shared_ptr<Game> readGame();
void sendInt(int value);
void sendString(const std::string& name);
void sendGame(std::shared_ptr<Game> game);
};