Hi everyone im trying to make a server for the first time and i've got a problem.
Apparently only one client can join.
I dont really know what is happening.
#include <SFML\Network.hpp>
#include <iostream>
unsigned short port = 6702;
bool open = true;
int main() {
sf::TcpListener listener;
std::vector<sf::TcpSocket*> clients;
if(listener.listen(port) != sf::Socket::Done) {
return -1;
}
std::cout << "Waiting for connections...\n";
while (open) {
sf::TcpSocket* newConnection = new sf::TcpSocket;
if(listener.accept(*newConnection) == sf::Socket::Done) {
clients.push_back(newConnection);
sf::Packet confirmation;
confirmation << true;
clients[clients.size()-1]->send(confirmation);
std::cout << "Player Joined! Players Online: " << clients.size() << "\n";
}
else {
delete newConnection;
}
for (auto& client : clients) {
sf::Packet packet;
sf::Socket::Status status = client->receive(packet);
if (status == sf::Socket::Done) {
for (auto& client2 : clients) {
if(client != client2) {
std::cout << "a2";
}
}
}
else if (status == sf::Socket::Disconnected) {
}
}
}
}
Thanks in advance.