Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] how to disconnect a certain client user from server
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] how to disconnect a certain client user from server

Scheduled Pinned Locked Moved General and Desktop
17 Posts 5 Posters 10.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kalster
    wrote on last edited by
    #8

    i guess i never made my point clear. lets say the user is joe. i want to boot (ban) only joe from the client. everyone else in the client is still able to post a message.

    at the server side. i know that joe is online. i need to boot him from the server.

    i cant use clients.remove(client) because client could be anyone. clients.remove("joe") give a tcpserver error.

    the server is online and the only needed information is what i gave in my above post.

    @ QMapIterator <QTcpSocket, int> test;
    QString nick = str;
    test.insert(nick, 1);
    str.remove(nick.toLower());
    @

    in the last line of code, i am trying to remove joe from the client from server.. but it is not working. i get an error that a string cannot be used, which is why i used the maplterator in the first place.

    from the server i need to only close the client joe. everyone else is still able to post. i would like to create a banning option for the server.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #9

      Please re-read Lukas' message. You are not giving enough information. I already pointed out the many issues and missing context of the small snippet you are posting, but yet you simply re-post it. You are telling us nothing about how users map to sockets, or where you keep that information your application. Yet you expect us to somehow know all that.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kalster
        wrote on last edited by
        #10

        header
        private:
        @QSet<QTcpSocket*> clients;
        QMap<QTcpSocket*,QString> users;@

        main.cpp
        my users are connected by...
        QTcpSocket client = (QTcpSocket)sender();
        clients.insert(client);
        clients is the current client connected.

        i remove the current user by...
        clients.remove(client);

        but i am not able to remove a username from the client.

        hope this helps.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #11

          As I'm still not quite sure about your problem I just assume that you want to get a specific QTcpSocket* stored in <code>users</code>, identified by the QString it associates with - which means you want to access a specific value, not key.

          This can be done by manually iterating over the values using QMapIterator, but to me the most painless way in your case will be using "qFind":http://www.youtube.com/watch?v=-xGGPfdQ-n4.
          @
          QMap<QTcpSocket*, QString>::iterator user = qFind(users.begin(), users.end(), "joe");
          if(user != users.end())
          {
          QTcpSocket* socket = user.key();
          QString name = user.value();
          }
          @
          Brain to terminal. Not tested. Exemplary.

          This thread is a prime example of the endless importance to obey the "smart questioning rules":http://www.catb.org/~esr/faqs/smart-questions.html. If the question would have been "How to find a value stored in a container" it has been answered in the first reply.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kalster
            wrote on last edited by
            #12

            Lukas Geyer with your code, i tried to remove your code with my code at the end of it. the user does not get disconnected.

            what more information do you need so that i can get this issue closed?

            @clients.remove(socket);
            users.remove(socket);@

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #13

              Of course <code>users.remove(socket)</code> doesn't close the connection to the client, it just removes the value <code>socket</code> from the collection <code>users</code>.

              If you take a look at the documentation of "QTcpSocket":http://developer.qt.nokia.com/doc/qt-4.8/qabstractsocket.html#close, which method might be suitable to close the connection?

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kalster
                wrote on last edited by
                #14

                ok. i will but i don't have time right now to try to close the socket or even look thoroughly into your code which looks great and should be what i am looking for. i will post my results later in the day.

                thank you for you patience

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kalster
                  wrote on last edited by
                  #15

                  I thought i did not have time but i did.

                  the code works great. I can now disconnect a selected user. thank you Lukas Geyer. you saved the day :)

                  edit: i forgot about closing the socket.

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kalster
                    wrote on last edited by
                    #16

                    ps: Andre, i fixed my few posts. they are now neater to read

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      troubalex
                      wrote on last edited by
                      #17

                      Thanks, folks. Let's try not to yell at each other and be constructive, both on the asking and the replying end.

                      All good, carry on. :)

                      THE CAKE IS A LIE
                      Web Community Manager - Qt Development Frameworks

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved