Hello guys!
I was wondering why the client are not sending the information to server when I have typed socket->send(..);
I would be glad if someone could take a look at my code and give me suggestion whats wrong.
In the last pice of code in the server code, thats is were i get my "Error" and dont recive the packet
The SERVER CODE:
std::cout << "Server Running" << std::endl;
//se om server får några connections från någon client, bara om dom pekar man kan säga att listener håller i connectins
sf::TcpListener listener;
//tar imot connections, så flera kan ta imot connections
sf::SocketSelector selector;
bool done = false;
//clienterna som ansluter sig till servern
std::vector<sf::TcpSocket*> clients;
int Connected;
unsigned short port;
std::cout << "Type the portnumber:";
std::cin >> port;
//listenern hör till denna port alltså ervern
listener.listen(port);
selector.add(listener);
while (!done)
{
if (selector.wait())
{
if (selector.isReady(listener))
{
sf::TcpSocket *socket = new sf::TcpSocket;
listener.accept(*socket);
sf::Packet ready;
bool isready = true;
ready << isready;
socket->send(ready);
sf::Packet packet;
std::string id;
if (socket->receive(packet) == sf::Socket::Done)
packet >> id;
std::cout << id << " Has connected to the room" << std::endl;
clients.push_back(socket);
selector.add(*socket);
sf::Packet leave;
int dis;
if (socket->receive(leave) == sf::Socket::Done)
{
leave >> dis;
selector.remove(*socket);
//std::cout << id << " " << "has left" << std::endl;
std::cout << dis << std::endl;
}
}
And this is what i want to send through my client to the server.
void Client::Leave()
{
sf::Packet leave;
int dis = true;
leave << dis;
socket->send(leave);
}