Frage zu Server mit mehreren Clients



  • Hallo,

    wie erstellt man einen Server, der mehrere clients bedienen kann?

    Ich meine damit, mein Server lauscht auf einen Port und wenn eine Verbindung kommt, nimmt er diese an.

    Kann ich dann für den nächsten client auf dem selben port lauschen?

    Wenn nein, wie schaffe ich es, dass sich jeder client nen anderen port wählt, wenn er nicht wissen kann, der wievielte client er sein wird?



  • warum liest du dir nicht ein tutorial durch bevor du hier fragst?



  • Kann ich dann für den nächsten client auf dem selben port lauschen?

    ja kannst du!

    wenn du dann irgendwann mal Threads brauchst, dann kann ich dir boost empfehlen:

    #include <boost/thread/thread.hpp>
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    void hello_world() {
    
            for(int i = 0; i < 10; i++)
            {
                    cout<<"Hello world, I'm a thread!"<< endl;
                    Sleep(100);
            }
    }
    
    void brown_fox() {
    
            for(int i = 0; i < 10; i++)
            {
                    cout <<"The quick brown fox jumps over the lazy dog"<< endl;
                    Sleep(50);
            }
    }
    
    int main(int argc, char* argv[]) {
            // start a new thread that calls the "hello_world" function
            boost::thread my_thread(&hello_world);
    
            // start a new thread that calls the "brown_fox" function
            boost::thread my_thread2(&brown_fox);
    
            // wait for the threads to finish
            my_thread.join();
            my_thread2.join();
    
            system("pause");
    
            return 0;
    }
    


  • Ne das mit den Threads läuft schon ohne boost!



  • tutorial Da gibts auch en tutorial wie man mehrer Clients bedient


Anmelden zum Antworten