very buggy system working, but only works properly with one client at a time due to recv blocking

This commit is contained in:
Kayne Ruse
2013-05-17 19:32:45 +10:00
parent 738320e88e
commit 24e48dec53
12 changed files with 153 additions and 42 deletions
+19 -13
View File
@@ -2,17 +2,10 @@
#include <stdexcept>
#include <iostream>
#include <algorithm>
using namespace std;
Server::Server() {
running = false;
}
Server::~Server() {
//
}
void Server::Init() {
NetworkInit();
@@ -34,7 +27,7 @@ void Server::Proc() {
}
void Server::Quit() {
for (auto it : sockVec) {
for (auto it : socketList) {
it->Close();
delete it;
}
@@ -46,12 +39,25 @@ void Server::HandleInput() {
//accept new connections
TCPSocket* sock = new TCPSocket;
if (servSock.Accept(sock)) {
sockVec.push_back(sock);
socketList.push_back(sock);
}
else {
delete sock;
}
//accept updates from the clients
//...
string input;
for_each(socketList.begin(), socketList.end(), [&input](TCPSocket* sock){ //why use for_each & lamdas?? to give logan a brain hemorrhage
char buffer[512];
memset(buffer, 0, 512);
sock->Recv(buffer, 512);
input += buffer;
});
//read the updates from the clients into internal containers
//...
if (input.size()) {
cout << "dumping input from the network" << endl;
cout << input << endl;
input.clear();
}
}
void Server::UpdateWorld() {
@@ -65,7 +71,7 @@ void Server::HandleOutput() {
//...
//selective updates to existing connectons
string s = "hello world";
for (auto it : sockVec) {
for (auto it : socketList) {
it->Send(s.c_str(), s.length());
}
}