-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.cpp
More file actions
49 lines (41 loc) · 1.39 KB
/
server.cpp
File metadata and controls
49 lines (41 loc) · 1.39 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
48
49
#include <iostream>
#include "enums/PackageTypeEnum.hpp"
#include "src/ArgParser/ArgParser.hpp"
#include "src/Connection/ServerDownloadConnection.hpp"
#include "src/Connection/ServerListConnection.hpp"
#include "src/Constants/Constants.hpp"
#include "src/Package/Package.hpp"
#include "src/RawSocket/RawSocket.hpp"
int main(int argc, char** argv) {
bool loopback = network::ArgParser::parseArguments(argc, argv);
network::RawSocket* rawSocket{new network::RawSocket{loopback}};
network::Package package;
while (true) {
rawSocket->recvPackage(package);
if (package.checkCrc()) {
switch (package.getType()) {
case network::PackageTypeEnum::LIST: {
network::ServerListConnection connection{rawSocket};
connection.run();
break;
}
case network::PackageTypeEnum::DOWNLOAD: {
std::string videoName;
for (size_t i = 0; i < package.getDataSize(); ++i)
videoName.append(1, static_cast<char>(package.getData()[i]));
network::ServerDownloadConnection connection{rawSocket, videoName};
connection.run();
break;
}
default: {
// Cleaning buffer loopback
break;
}
}
} else {
network::Package nack{network::Constants::INIT_MARKER, 0, 0, network::PackageTypeEnum::NACK};
rawSocket->sendPackage(nack);
}
}
delete rawSocket;
}