Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - FlyPT

Pages: [1]
1
Network / Re: SFML Server doesn't accept more than one client
« on: July 27, 2015, 08:59:06 pm »
I put every socket in non blocking but now it doesnt receive data from players.

2
Network / SFML Server doesn't accept more than one client
« on: July 27, 2015, 10:02:28 am »
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.

Pages: [1]