-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.cpp
More file actions
52 lines (46 loc) · 1.43 KB
/
Server.cpp
File metadata and controls
52 lines (46 loc) · 1.43 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
50
51
52
#include"Server.h"
#define DEBUG
Server::Server() {
cout << "Server Online!\n";
}
void Server::stepNetwork() {
ZeroMemory(buffer, TFTP_BUFLENGTH);
status = recvfrom(serverSocket, buffer, TFTP_BUFLENGTH, 0, (struct sockaddr*)&clientAddr, &clientAddrSize);
if (SOCKET_ERROR != status) {
// we have recieved something
//cout << int(buffer[1]) << endl;
//check to see if its the same client
bool lfound = false;
for (auto myClient : clients) {
if (myClient->getPort() == clientAddr.sin_port) { //takes care of matching TID's and discarding other packets
lfound = true;
myClient->setBuffer(buffer);
myClient->setBytes(status);
break;
}
}
// no client found so creating a new client and adding to list
if (!lfound) {
clients.push_back(new Client( buffer, serverSocket, clientAddr ));
}
}
// if so resume the activity
vector<vector<Client*>::iterator> clearRequests;
//cout << clients.size() << endl;
for (auto myClient = clients.begin(); myClient != clients.end(); ++myClient) {
(*myClient)->stepClientStatus();
(*myClient)->stepClient();
//Find if the client timedout or nomally terminated
if (TIMED_OUT == (*myClient)->getClientStatus()) {
clearRequests.push_back(myClient);
delete (*myClient);
}
}
// Kill the timed out clinets
for (auto& i : clearRequests) {
clients.erase(i);
}
}
Server::~Server() {
cout << "Server Offline";
}