very buggy system working, but only works properly with one client at a time due to recv blocking
This commit is contained in:
+19
-13
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user