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 - Artyom

Pages: [1]
1
Network / Re: i found some unexpectable behavior of wait() function
« on: April 20, 2018, 12:33:28 am »
P.s i’m trying to run my program by local network and start at single and different computers. It gives same results

2
Network / Re: i found some unexpectable behavior of wait() function
« on: April 20, 2018, 12:30:19 am »
Ok, thanks for reply
This function returns immediately because listener can receive a connection.
But why when first client trying to connect it wrote the message of the case when we are connected and at server it don’t run any of cases(neither client connected message, nor error message), which means what isReady function returns false(this contradicts the fact that any of the sockets are ready) and continues to run the loop without waiting timeout, which means what listener can receive new connection, but when i’m trying to connect to second client, it wrote the error-message and at server it still run the loops, which are doing nothing. So, what is my problem?

3
Network / i found some unexpectable behavior of wait() function
« on: April 17, 2018, 09:59:44 pm »
Hi everyone! i writing my client-server app and use TcpSockets with SocketSelector and thier functions wait() and isReady()
when i trying to connect on client part, it returns Socket::Status::Done and for sended messages also, but on server wait function in loop always return false by the way i checked and it didn't wait this 5 seconds: "if (selector.wait(sf::seconds(5)))". how is it possible? p.s. listener.listen(50000) returned Socket::Status::Done

here the server main loop code:

for (;;sleep(sf::milliseconds(100)))  
   {
      if (isServerClosing)
      {
         cout << "we are closing!\n";
         break;  
      }

      if (selector.wait(sf::seconds(5)))               // Make the selector wait for data on any socket
      {
         if (selector.isReady(listener))                        //if listener ready to recv new client
         {      
            TcpSocket* client = new TcpSocket;
            if (listener.accept(*client) == sf::Socket::Status::Done)      // The listener is ready to accept new client
            {
               clients.push_back(client);
               selector.add(*client);                        //container for pointers on Sockets
               cout << clients.size() << ". client connected: " << (*client).getRemoteAddress() << " and port: " << (*client).getRemotePort() << '\n';
            }
            else
            {
               // Error, we won't get a new connection, delete the socket
               cout << "error!\n";
               delete client;
            }
         }
         else                                                        //check for ready for recv sockets
         {
               for (std::vector<TcpSocket*>::iterator it = clients.begin(); it != clients.end(); ++it)
               {
                  if (selector.isReady(**it))
                  {
                     Packet packet;                           //create packet for receiving information
                     Socket::Status status = (**it).receive(packet);
                     if (status == Socket::Status::Done)
                     {
                        packet >> msgFromClients;
                        cout << msgFromClients;         //print message on server
                        //send for clients
                        for (std::vector<TcpSocket*>::iterator it_temp = clients.begin(); it_temp != clients.end(); it_temp++)
                        {
                           if (it_temp != it)
                           {
                              if ((**it).send(packet) == Socket::Status::Disconnected)
                              {
                                 cout << "client AFK";         //delete inactive users
                                 (**it).disconnect();
                                 delete *it;
                                 clients.erase(it);
                                 selector.remove(**it);
                              }
                           }
                        }
                     }
                     else
                        if (status == Socket::Status::Disconnected)
                        {
                           cout << "client AFK";         //delete inactive users
                           (**it).disconnect();
                           delete *it;
                           clients.erase(it);
                           selector.remove(**it);
                        }
                  }
               }
         }
     
      }
   }

please, help me

Pages: [1]