TCP Socket



  • Hallo,

    ich habe mir in c++ einen TCP Socket aufgemacht..

    dieser läuft in einer schleife...

    allerdings bleibt dieser bei accept() hängen und wartet dort auf die Anfrage vom Client.

    Ich will jetzt aber noch andere Sachen in der schleife ablaufen lassen, nur leider komm ich dort erst garnicht hin da er ja bei accept() wartet.

    wie mache ich das am besten?


  • Mod

    Welches Betriebssystem? Zwar können alle Socketimplementierungen ungefähr das gleiche, aber eventuell unterscheiden sich Details, was wie geht. Aber auf jeden Fall gibt es viele Lösungen. Ich zitiere mal aus der Linux-Manpage zu accept:

    If no pending connections are present on the queue, and the socket is not marked as nonblocking, accept() blocks the caller until a connection is present. If the socket is marked nonblocking and no pending connections are present on the queue, accept() fails with the error EAGAIN or EWOULDBLOCK.

    In order to be notified of incoming connections on a socket, you can use select(2) or poll(2). A readable event will be delivered when a new connection is attempted and you may then call accept() to get a socket for that connection. Alternatively, you can set the socket to deliver SIGIO when activity occurs on a socket; see socket(7) for details.

    Winsockets sind nicht wesentlich anders.

    Du kannst natürlich auch mit mehreren Threads arbeiten, wenn deine Programmlogik eher nach solch einer Art des Ablaufs verlangen sollte.


Anmelden zum Antworten