-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnection.cpp
More file actions
47 lines (38 loc) · 1.12 KB
/
Copy pathConnection.cpp
File metadata and controls
47 lines (38 loc) · 1.12 KB
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
//
// Created by Matt on 10/09/2016.
//
#include <iostream>
#include "Connection.h"
Connection::Connection(UDPAddress remoteAddress, UDPSocket *socket) : remoteAddress(remoteAddress), socket(socket) {
packetQueue = std::queue<Packet *>();
}
int Connection::connect() {
unsigned short timeout = 10; //Seconds before aborting
while(!connected) {
//Connect
}
}
bool Connection::isConnected() {
return connected;
}
void Connection::addPacket(Packet *packet) {
packetQueue.push(packet);
}
void Connection::sendPacket(Packet *packet) {
std::cout << "Sending packet of type: " << packet->getType() << std::endl;
char *buffer = (char *) calloc(sizeof(char), 1024);
PacketSerialiser serialiser = PacketSerialiser(buffer, sizeof(char) * 1024);
packet->serialise(&serialiser);
socket->send(remoteAddress, serialiser.getBuffer(), serialiser.getLength());
}
bool Connection::hasPacket() {
return !packetQueue.empty();
}
Packet *Connection::getPacket() {
Packet *p = packetQueue.front();
packetQueue.pop();
return p;
}
UDPAddress Connection::getAddress() {
return remoteAddress;
}